diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 73939d1..3f12fc7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,21 @@ # yamllint disable rule:line-length --- -name: Release +name: Release TEST on: + workflow_dispatch: + inputs: + tag: + description: Release tag (vX.Y.Z) + required: true + draft: + description: Dry run mode (true/false) + required: false + default: !!str true + prerelease: + description: Mark the release as a prerelease (true/false) + required: false + default: !!str true push: tags: - v*.*.* @@ -12,16 +25,70 @@ permissions: concurrency: group: release + cancel-in-progress: true jobs: - create-release: + release: permissions: contents: write runs-on: ubuntu-latest + steps: - name: Clone the repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + uses: actions/checkout@2e5b7cfdf3b7c29bfa124b5f44ea66c2ba98d1a30eae32b2d6e74c23f44ef3d4 # v4.1.0 + + - id: version_source + name: Determine version source + run: | + if [[ '${{ github.event_name }}' == workflow_dispatch ]]; then + echo 'release_tag=${{ github.event.inputs.tag }}' >>"${GITHUB_OUTPUT}" + else + echo "release_tag=${GITHUB_REF_NAME}" >>"${GITHUB_OUTPUT}" + fi + + - id: extract_version + name: Extract version from tag + run: | + version='${{ steps.version_source.outputs.release_tag }}' + version="${version#v}" + major_version="${version%%.*}" + echo "version=${version}" >>"${GITHUB_OUTPUT}" + echo "major_version=${major_version}" >>"${GITHUB_OUTPUT}" + + - name: Update README.md version string + run: | + sed -i -E "s@(uses: .*/github-action-markdown-cli@)v[0-9]+\.[0-9]+\.[0-9]+@\1v${{ steps.extract_version.outputs.version }}@" README.md + + - name: Update package.json version field + run: | + jq --arg v '${{ steps.extract_version.outputs.version }}' '.version = $v' package.json >package.json.tmp && + mv package.json.tmp package.json + + - name: Commit files if changed + run: | + git config user.name '${{ github.actor }}' + git config user.email '${{ github.actor }}@users.noreply.github.com' + git add README.md package.json + git commit -m 'Update version to v${{ steps.extract_version.outputs.version }}' || echo 'No changes to commit' + git push origin '${{ github.event.repository.default_branch }}' + + - if: github.event_name != 'workflow_dispatch' || github.event.inputs.draft != 'true' + name: Conditionally move version tag forward + run: | + git tag --force '${{ steps.version_source.outputs.release_tag }}' HEAD + git push origin '${{ steps.version_source.outputs.release_tag }}' --force + - name: Create the release - uses: softprops/action-gh-release@72f2c25fcb47643c292f7107632f7a47c1df5cd8 # v2.3.2 + run: | + args=(--fail-on-no-commits --notes-from-tag) # TODO: --verify-tag + [[ '${{ github.event.inputs.draft }}' == true ]] && args+=(--draft) + [[ '${{ github.event.inputs.prerelease }}' == true ]] && args+=(--prerelease) + gh release create '${{ steps.version_source.outputs.release_tag }}' "${args[@]}" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - if: github.event_name != 'workflow_dispatch' || github.event.inputs.draft != 'true' + name: Conditionally move major version tag + run: |- + git tag --force 'v${{ steps.extract_version.outputs.major_version }}' "${GITHUB_SHA}" + git push origin 'v${{ steps.extract_version.outputs.major_version }}' --force diff --git a/.github/workflows/versioning.yml b/.github/workflows/versioning.yml deleted file mode 100644 index f02461b..0000000 --- a/.github/workflows/versioning.yml +++ /dev/null @@ -1,24 +0,0 @@ -# yamllint disable rule:line-length ---- -name: Tag Versioning - -on: - release: - types: - - published - - edited - -permissions: - contents: read - -concurrency: - group: versioning - -jobs: - actions-tagger: - permissions: - contents: write - pull-requests: write - runs-on: ubuntu-latest - steps: - - uses: Actions-R-Us/actions-tagger@330ddfac760021349fef7ff62b372f2f691c20fb # v2.0.3