|
| 1 | +name: Trigger release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version-bump: |
| 7 | + description: 'Whether to bump major, minor or patch version' |
| 8 | + required: false |
| 9 | + default: patch |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - major |
| 13 | + - minor |
| 14 | + - patch |
| 15 | + desired-version: |
| 16 | + description: 'Version to be released; if specified, version-bump will be ignored' |
| 17 | + required: false |
| 18 | + default: '' |
| 19 | + |
| 20 | +concurrency: trigger-release |
| 21 | + |
| 22 | +env: |
| 23 | + TAG_PREFIX: v |
| 24 | + INITIAL_TAG: v0.1.0 |
| 25 | + SEMVER_VERSION: 3.4.0 |
| 26 | + |
| 27 | +defaults: |
| 28 | + run: |
| 29 | + shell: bash |
| 30 | + |
| 31 | +jobs: |
| 32 | + release: |
| 33 | + name: Trigger release |
| 34 | + runs-on: ubuntu-22.04 |
| 35 | + permissions: |
| 36 | + contents: write |
| 37 | + |
| 38 | + steps: |
| 39 | + - name: Validate ref |
| 40 | + run: | |
| 41 | + if [ "${{ github.ref }}" != refs/heads/main ]; then |
| 42 | + >&2 echo "Invalid ref: ${{ github.ref }} (expected: refs/heads/main)" |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | +
|
| 46 | + - name: Checkout repository |
| 47 | + uses: actions/checkout@v3 |
| 48 | + with: |
| 49 | + token: ${{ secrets.WORKFLOW_USER_GH_TOKEN }} |
| 50 | + |
| 51 | + - name: Setup semver |
| 52 | + uses: ./.github/actions/setup-semver |
| 53 | + with: |
| 54 | + version: ${{ env.SEMVER_VERSION }} |
| 55 | + install-directory: ${{ runner.temp }}/bin |
| 56 | + |
| 57 | + - name: Determine current release |
| 58 | + id: get_current_release |
| 59 | + uses: ./.github/actions/get-highest-tag |
| 60 | + with: |
| 61 | + prefix: ${{ env.TAG_PREFIX }} |
| 62 | + |
| 63 | + - name: Determine target release |
| 64 | + id: get_target_release |
| 65 | + run: | |
| 66 | + desired_version=${{ inputs.desired-version }} |
| 67 | + current_version=${{ steps.get_current_release.outputs.version }} |
| 68 | + version_bump=${{ inputs.version-bump }} |
| 69 | +
|
| 70 | + if [ -z "$desired_version" ]; then |
| 71 | + case $version_bump in |
| 72 | + major|minor|patch) |
| 73 | + # ok |
| 74 | + ;; |
| 75 | + *) |
| 76 | + >&2 echo "Invalid input: version-bump ($version_bump)." |
| 77 | + exit 1 |
| 78 | + esac |
| 79 | + if [ -z "$current_version" ]; then |
| 80 | + version=${INITIAL_TAG/#$TAG_PREFIX/} |
| 81 | + tag=$INITIAL_TAG |
| 82 | + else |
| 83 | + version=$(semver bump $version_bump $current_version) |
| 84 | + tag=$TAG_PREFIX$version |
| 85 | + fi |
| 86 | + else |
| 87 | + if [[ $desired_version =~ ^$TAG_PREFIX([0-9].*)$ ]]; then |
| 88 | + version=${BASH_REMATCH[1]} |
| 89 | + tag=$desired_version |
| 90 | + else |
| 91 | + >&2 echo "Invalid input: desired-version ($desired_version) should start with $TAG_PREFIX." |
| 92 | + exit 1 |
| 93 | + fi |
| 94 | + if [ "$(semver validate $version)" != valid ]; then |
| 95 | + >&2 echo "Invalid input: desired-version ($version) is not a valid semantic version." |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + if [ "$(semver compare $version $current_version)" -le 0 ]; then |
| 99 | + >&2 echo "Invalid input: desired-version ($version) should be higher than current version ($current_version)." |
| 100 | + exit 1 |
| 101 | + fi |
| 102 | + fi |
| 103 | +
|
| 104 | + echo "Target version: $version" |
| 105 | + echo "Target tag: $tag" |
| 106 | + echo "version=$version" >> $GITHUB_OUTPUT |
| 107 | + echo "tag=$tag" >> $GITHUB_OUTPUT |
| 108 | +
|
| 109 | + - name: Determine target commit |
| 110 | + id: get_target_commit |
| 111 | + run: | |
| 112 | + sha=$(git rev-parse HEAD) |
| 113 | + echo "Target commit: $sha" |
| 114 | + echo "sha=$sha" >> $GITHUB_OUTPUT |
| 115 | +
|
| 116 | + - name: Wait for check suites to complete |
| 117 | + uses: sap-contributions/await-check-suites@master |
| 118 | + with: |
| 119 | + ref: ${{ steps.get_target_commit.outputs.sha }} |
| 120 | + intervalSeconds: 10 |
| 121 | + timeoutSeconds: 1800 |
| 122 | + failStepIfUnsuccessful: true |
| 123 | + appSlugFilter: github-actions |
| 124 | + |
| 125 | + - name: Create Release |
| 126 | + uses: softprops/action-gh-release@v1 |
| 127 | + with: |
| 128 | + tag_name: ${{ steps.get_target_release.outputs.tag }} |
| 129 | + draft: false |
| 130 | + prerelease: false |
| 131 | + target_commitish: ${{ steps.get_target_commit.outputs.sha }} |
| 132 | + token: ${{ secrets.WORKFLOW_USER_GH_TOKEN }} |
| 133 | + generate_release_notes: false |
| 134 | + |
0 commit comments