11# yamllint disable rule:line-length
22---
3- name : Release
3+ name : Release TEST
44
55on :
6+ workflow_dispatch :
7+ inputs :
8+ tag :
9+ description : Release tag (vX.Y.Z)
10+ required : true
11+ draft :
12+ description : Dry run mode (true/false)
13+ required : false
14+ default : !!str true
15+ prerelease :
16+ description : Mark the release as a prerelease (true/false)
17+ required : false
18+ default : !!str true
619 push :
720 tags :
821 - v*.*.*
@@ -12,16 +25,70 @@ permissions:
1225
1326concurrency :
1427 group : release
28+ cancel-in-progress : true
1529
1630jobs :
17- create- release :
31+ release :
1832 permissions :
1933 contents : write
2034 runs-on : ubuntu-latest
35+
2136 steps :
2237 - name : Clone the repository
23- uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
38+ uses : actions/checkout@2e5b7cfdf3b7c29bfa124b5f44ea66c2ba98d1a30eae32b2d6e74c23f44ef3d4 # v4.1.0
39+
40+ - id : version_source
41+ name : Determine version source
42+ run : |
43+ if [[ '${{ github.event_name }}' == workflow_dispatch ]]; then
44+ echo 'release_tag=${{ github.event.inputs.tag }}' >>"${GITHUB_OUTPUT}"
45+ else
46+ echo "release_tag=${GITHUB_REF_NAME}" >>"${GITHUB_OUTPUT}"
47+ fi
48+
49+ - id : extract_version
50+ name : Extract version from tag
51+ run : |
52+ version='${{ steps.version_source.outputs.release_tag }}'
53+ version="${version#v}"
54+ major_version="${version%%.*}"
55+ echo "version=${version}" >>"${GITHUB_OUTPUT}"
56+ echo "major_version=${major_version}" >>"${GITHUB_OUTPUT}"
57+
58+ - name : Update README.md version string
59+ run : |
60+ sed -i -E "s@(uses: .*/github-action-markdown-cli@)v[0-9]+\.[0-9]+\.[0-9]+@\1v${{ steps.extract_version.outputs.version }}@" README.md
61+
62+ - name : Update package.json version field
63+ run : |
64+ jq --arg v '${{ steps.extract_version.outputs.version }}' '.version = $v' package.json >package.json.tmp &&
65+ mv package.json.tmp package.json
66+
67+ - name : Commit files if changed
68+ run : |
69+ git config user.name '${{ github.actor }}'
70+ git config user.email '${{ github.actor }}@users.noreply.github.com'
71+ git add README.md package.json
72+ git commit -m 'Update version to v${{ steps.extract_version.outputs.version }}' || echo 'No changes to commit'
73+ git push origin '${{ github.event.repository.default_branch }}'
74+
75+ - if : github.event_name != 'workflow_dispatch' || github.event.inputs.draft != 'true'
76+ name : Conditionally move version tag forward
77+ run : |
78+ git tag --force '${{ steps.version_source.outputs.release_tag }}' HEAD
79+ git push origin '${{ steps.version_source.outputs.release_tag }}' --force
80+
2481 - name : Create the release
25- uses : softprops/action-gh-release@72f2c25fcb47643c292f7107632f7a47c1df5cd8 # v2.3.2
82+ run : |
83+ args=(--fail-on-no-commits --notes-from-tag) # TODO: --verify-tag
84+ [[ '${{ github.event.inputs.draft }}' == true ]] && args+=(--draft)
85+ [[ '${{ github.event.inputs.prerelease }}' == true ]] && args+=(--prerelease)
86+ gh release create '${{ steps.version_source.outputs.release_tag }}' "${args[@]}"
2687 env :
2788 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
89+
90+ - if : github.event_name != 'workflow_dispatch' || github.event.inputs.draft != 'true'
91+ name : Conditionally move major version tag
92+ run : |-
93+ git tag --force 'v${{ steps.extract_version.outputs.major_version }}' "${GITHUB_SHA}"
94+ git push origin 'v${{ steps.extract_version.outputs.major_version }}' --force
0 commit comments