|
| 1 | +# yamllint disable rule:line-length |
| 2 | +--- |
| 3 | +name: Release TEST |
| 4 | + |
| 5 | +on: |
| 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: Dry run mode (true/false) |
| 17 | + required: false |
| 18 | + default: !!str true |
| 19 | + push: |
| 20 | + tags: |
| 21 | + - v*.*.* |
| 22 | + |
| 23 | +permissions: |
| 24 | + contents: read |
| 25 | + |
| 26 | +concurrency: |
| 27 | + group: release |
| 28 | + cancel-in-progress: true |
| 29 | + |
| 30 | +jobs: |
| 31 | + release: |
| 32 | + permissions: |
| 33 | + contents: write |
| 34 | + runs-on: ubuntu-latest |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Clone the repository |
| 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=${{ 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 '.version = "${{ steps.extract_version.outputs.version }}"' 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 master |
| 74 | +
|
| 75 | + - if: github.event_name != 'workflow_dispatch' || 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 | +
|
| 81 | + - name: Create the release |
| 82 | + run: | |
| 83 | + args=(--generate-notes) |
| 84 | + [[ '${{ inputs.draft }}' == true ]] && args+=(--draft) |
| 85 | + [[ '${{ inputs.prerelease }}' == true ]] && args+=(--prerelease) |
| 86 | + gh release create '${{ steps.version_source.outputs.release_tag }}' "${args[@]}" |
| 87 | + env: |
| 88 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + |
| 90 | + - if: github.event_name != 'workflow_dispatch' || 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