github.com/vmware/govmomi@v0.51.0/.github/workflows/govmomi-release.yaml (about) 1 name: Release 2 3 permissions: 4 contents: read 5 issues: write 6 pull-requests: write 7 actions: write 8 checks: write 9 deployments: write 10 statuses: write 11 12 on: 13 workflow_dispatch: 14 inputs: 15 tag: 16 description: Release (Uses this non-existing semantic version tag.) 17 required: true 18 type: string 19 default: v0.99.0 20 dryrun: 21 description: Dry Run (Verifies workflow without pushing a release.) 22 type: boolean 23 required: false 24 default: true 25 26 jobs: 27 release: 28 name: Create Release 29 runs-on: ubuntu-latest 30 permissions: 31 contents: write 32 timeout-minutes: 60 33 outputs: 34 latesttag: ${{ steps.tag.outputs.islatest }} 35 steps: 36 - name: Docker Login 37 run: docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} 38 - name: Checkout Repository 39 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 40 with: 41 fetch-depth: 0 # for CHANGELOG 42 ref: ${{ github.ref }} # branch provided on dispatch 43 - name: Validate Branch and Tag 44 run: | 45 # do not allow release on main branch 46 if [[ ${{ github.ref }} == refs/heads/main ]]; then 47 echo "::error:: release must be done on a release branch" 48 exit 1 49 fi 50 51 # check it starts with "v" 52 if [[ ${{ inputs.tag }} != v* ]]; then 53 echo "::error:: tag must have a \"v\" prefix" 54 exit 1 55 fi 56 57 # check it does not exist 58 if [[ $(git tag -l ${{ inputs.tag }} ) ]]; then 59 echo "::error:: tag already exists" 60 exit 1 61 fi 62 63 # set tag environment variable 64 echo "TAG=${{ inputs.tag }}" >> $GITHUB_ENV 65 - name: Setup Go 66 uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 67 with: 68 go-version: '1.23' 69 - name: Update version.go 70 run: | 71 # strip semantic v 72 export GOVMOMI_VERSION=${TAG#"v"} 73 74 sed -i "s/ClientVersion =.*/ClientVersion = \"$GOVMOMI_VERSION\"/" internal/version/version.go 75 git --no-pager diff internal/version/version.go 76 77 # configure author 78 # https://github.community/t/github-actions-bot-email-address/17204/6 79 git config --local user.email 41898282+github-actions[bot]@users.noreply.github.com 80 git config --local user.name "GitHub Action" 81 82 # commit changes 83 git add internal/version/version.go 84 git commit -s -m "chore: Update version.go for ${TAG}" 85 - name: Create Tag 86 id: tag 87 run: | 88 # create new tag 89 git tag -a ${TAG} -m "Release ${TAG}" 90 91 # find latest tag sorted by semver ref 92 LATEST=$(git tag --sort=v:refname | tail -1) 93 94 # check whether the new tag is also the latest 95 if [[ $LATEST == $TAG ]]; then 96 echo "islatest=true >> $GITHUB_OUTPUT" 97 else 98 echo "islatest=false >> $GITHUB_OUTPUT" 99 fi 100 - name: Push to Release Branch 101 if: ${{ !inputs.dryrun }} 102 env: 103 GOVMOMI_RELEASE: ${{ secrets.GOVMOMI_RELEASE }} 104 run: | 105 git remote set-url origin https://x-access-token:${GOVMOMI_RELEASE}@github.com/${{ github.repository }} 106 git push --atomic --follow-tags origin ${{ github.ref }} 107 - name: Create Release CHANGELOG 108 env: 109 IMAGE: quay.io/git-chglog/git-chglog 110 # https://quay.io/repository/git-chglog/git-chglog from tag v0.14.2 111 IMAGE_SHA: 998e89dab8dd8284cfff5f8cfb9e9af41fe3fcd4671f2e86a180e453c20959e3 112 run: | 113 # generate CHANGELOG for this Github release tag only 114 docker run --rm -v $PWD:/workdir ${IMAGE}@sha256:${IMAGE_SHA} -o RELEASE_CHANGELOG.md --sort semver --tag-filter-pattern '^v[0-9]+' ${TAG} 115 - name: Archive CHANGELOG 116 uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 117 continue-on-error: true 118 with: 119 name: CHANGELOG 120 path: | 121 ./RELEASE_CHANGELOG.md 122 retention-days: 14 123 - name: Simulate Release without Pushing Artifacts 124 if: ${{ inputs.dryrun }} 125 uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0 126 env: 127 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 128 with: 129 version: latest 130 args: release --snapshot --clean --release-notes RELEASE_CHANGELOG.md 131 - name: Create Release 132 if: ${{ !inputs.dryrun }} 133 uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0 134 env: 135 GITHUB_TOKEN: ${{ secrets.GOVMOMI_RELEASE }} 136 with: 137 version: latest 138 args: release --clean --release-notes RELEASE_CHANGELOG.md # will push artefacts and container images 139 pull-request: 140 needs: release 141 name: Create CHANGELOG.md PR 142 runs-on: ubuntu-latest 143 permissions: 144 contents: write 145 continue-on-error: true 146 # Only update CHANGELOG for latest semver tag. 147 if: ${{ !inputs.dryrun && needs.release.outputs.latesttag == 'true' }} 148 steps: 149 - name: Checkout Repository 150 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 151 with: 152 fetch-depth: 0 # for CHANGELOG 153 ref: main 154 - name: Commit CHANGELOG 155 env: 156 IMAGE: quay.io/git-chglog/git-chglog 157 # https://quay.io/repository/git-chglog/git-chglog from tag v0.14.2 158 IMAGE_SHA: 998e89dab8dd8284cfff5f8cfb9e9af41fe3fcd4671f2e86a180e453c20959e3 159 run: | 160 # update CHANGELOG 161 docker run --rm -v $PWD:/workdir ${IMAGE}@sha256:${IMAGE_SHA} -o CHANGELOG.md --sort semver --tag-filter-pattern '^v[0-9]+' -t .chglog/CHANGELOG.tpl.md 162 - name: Create Pull Request 163 id: cpr 164 uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8 165 with: 166 commit-message: "Update CHANGELOG for ${{ inputs.tag }}" 167 delete-branch: true 168 title: "Update CHANGELOG for ${{ inputs.tag }}" 169 signoff: true 170 draft: false 171 body: | 172 ### Update CHANGELOG.md for new release. 173 174 > **Note** 175 > Due to a [limitation](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#triggering-further-workflow-runs) in Github Actions please **close and immediately reopen** this PR to trigger the required workflow checks before merging. 176 - name: Pull Request Information 177 run: | 178 echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" 179 echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"