|
| 1 | +name: ODH Release |
| 2 | +# Creates a release branch from main (or a specific commit), optionally tags it, |
| 3 | +# and creates a GitHub release with auto-generated release notes. |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + release_branch: |
| 9 | + description: 'Name of the release branch (e.g. release-v3.5.0, release-v3.4.0-ea1)' |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + source_ref: |
| 13 | + description: 'Source commit SHA to create the release branch from. Leave empty to use the latest commit on main.' |
| 14 | + required: false |
| 15 | + type: string |
| 16 | + default: '' |
| 17 | + create_tag: |
| 18 | + description: 'Create a tag from the release branch? Tag will be derived from branch name (e.g. release-v3.5.0 -> v3.5.0)' |
| 19 | + required: true |
| 20 | + type: boolean |
| 21 | + default: false |
| 22 | + create_release: |
| 23 | + description: 'Create a GitHub release with auto-generated release notes? (requires create_tag)' |
| 24 | + required: true |
| 25 | + type: boolean |
| 26 | + default: false |
| 27 | + |
| 28 | +env: |
| 29 | + DEFAULT_BRANCH: main |
| 30 | + |
| 31 | +jobs: |
| 32 | + create-release-branch: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + permissions: |
| 35 | + contents: write |
| 36 | + steps: |
| 37 | + - name: Validate branch name |
| 38 | + run: | |
| 39 | + BRANCH="${{ inputs.release_branch }}" |
| 40 | + if [[ ! "$BRANCH" =~ ^release-v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then |
| 41 | + echo "::error::Invalid branch name '${BRANCH}'. Must match pattern 'release-v<major>.<minor>.<patch>[-<prerelease>]' (e.g. release-v3.5.0, release-v3.4.0-ea1)" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + echo "Branch name '${BRANCH}' is valid." |
| 45 | +
|
| 46 | + - name: Checkout ${{ env.DEFAULT_BRANCH }} |
| 47 | + uses: actions/checkout@v6 |
| 48 | + with: |
| 49 | + ref: ${{ env.DEFAULT_BRANCH }} |
| 50 | + fetch-depth: 0 |
| 51 | + |
| 52 | + - name: Create release branch |
| 53 | + run: | |
| 54 | + BRANCH="${{ inputs.release_branch }}" |
| 55 | + SOURCE_REF="${{ inputs.source_ref }}" |
| 56 | + if [[ -n "${SOURCE_REF}" ]]; then |
| 57 | + echo "Creating release branch from SHA: ${SOURCE_REF}" |
| 58 | + git checkout "${SOURCE_REF}" |
| 59 | + else |
| 60 | + echo "Creating release branch from latest ${{ env.DEFAULT_BRANCH }}" |
| 61 | + fi |
| 62 | + git checkout -b "${BRANCH}" |
| 63 | + git push origin "${BRANCH}" |
| 64 | + echo "::notice::Created release branch '${BRANCH}' from ${SOURCE_REF:-${{ env.DEFAULT_BRANCH }}}" |
| 65 | +
|
| 66 | + tag-release: |
| 67 | + needs: create-release-branch |
| 68 | + if: inputs.create_tag |
| 69 | + runs-on: ubuntu-latest |
| 70 | + permissions: |
| 71 | + contents: write |
| 72 | + steps: |
| 73 | + - name: Checkout release branch |
| 74 | + uses: actions/checkout@v6 |
| 75 | + with: |
| 76 | + ref: ${{ inputs.release_branch }} |
| 77 | + fetch-depth: 0 |
| 78 | + |
| 79 | + - name: Derive tag and push |
| 80 | + id: derive-tag |
| 81 | + run: | |
| 82 | + BRANCH="${{ inputs.release_branch }}" |
| 83 | + TAG="${BRANCH#release-}" |
| 84 | + echo "Tagging release branch '${BRANCH}' as '${TAG}'" |
| 85 | + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" |
| 86 | +
|
| 87 | + git tag "${TAG}" |
| 88 | + git push origin "${TAG}" |
| 89 | + echo "::notice::Created and pushed tag '${TAG}'" |
| 90 | + outputs: |
| 91 | + tag: ${{ steps.derive-tag.outputs.tag }} |
| 92 | + |
| 93 | + create-release: |
| 94 | + needs: tag-release |
| 95 | + if: inputs.create_tag && inputs.create_release |
| 96 | + runs-on: ubuntu-latest |
| 97 | + permissions: |
| 98 | + contents: write |
| 99 | + steps: |
| 100 | + - name: Create GitHub release |
| 101 | + uses: softprops/action-gh-release@v2 |
| 102 | + with: |
| 103 | + tag_name: ${{ needs.tag-release.outputs.tag }} |
| 104 | + name: ODH release ${{ needs.tag-release.outputs.tag }} |
| 105 | + generate_release_notes: true |
| 106 | + prerelease: ${{ contains(needs.tag-release.outputs.tag, '-') }} |
0 commit comments