github.com/vmware/govmomi@v0.37.1/.github/workflows/govmomi-release.yaml (about) 1 # Copyright (c) 2021 VMware, Inc. All Rights Reserved. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 name: Release 16 17 on: 18 workflow_dispatch: 19 inputs: 20 tag: 21 description: 'Create release using this non-existing semantic tag for the specified ref' 22 required: true 23 type: string 24 default: 'v0.99.0' 25 dryrun: 26 description: 'Verify release workflow without pushing any changes (catches most but not all errors)' 27 type: boolean 28 required: false 29 default: true 30 31 jobs: 32 release: 33 name: Create Release 34 runs-on: ubuntu-20.04 35 timeout-minutes: 60 36 outputs: 37 latesttag: ${{ steps.tag.outputs.islatest }} 38 39 steps: 40 - name: Docker Login 41 run: docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} 42 43 - name: Checkout 44 uses: actions/checkout@v4 45 with: 46 fetch-depth: 0 # for CHANGELOG 47 ref: ${{ github.ref }} # branch provided on dispatch 48 49 - name: Validate branch and tag 50 run: | 51 # do not allow release on main branch 52 if [[ ${{ github.ref }} == refs/heads/main ]]; then 53 echo "::error:: release must be done on a release branch" 54 exit 1 55 fi 56 57 # check it starts with "v" 58 if [[ ${{ inputs.tag }} != v* ]]; then 59 echo "::error:: tag must have a \"v\" prefix" 60 exit 1 61 fi 62 63 # check it does not exist 64 if [[ $(git tag -l ${{ inputs.tag }} ) ]]; then 65 echo "::error:: tag already exists" 66 exit 1 67 fi 68 69 # set tag environment variable 70 echo "TAG=${{ inputs.tag }}" >> $GITHUB_ENV 71 72 - name: Set up Go 73 uses: actions/setup-go@v5 74 with: 75 go-version: '1.20' 76 77 - name: Update version.go 78 run: | 79 # strip semantic v 80 export GOVMOMI_VERSION=${TAG#"v"} 81 82 sed -i "s/ClientVersion =.*/ClientVersion = \"$GOVMOMI_VERSION\"/" internal/version/version.go 83 git --no-pager diff internal/version/version.go 84 85 # configure author 86 # https://github.community/t/github-actions-bot-email-address/17204/6 87 git config --local user.email 41898282+github-actions[bot]@users.noreply.github.com 88 git config --local user.name "GitHub Action" 89 90 # commit changes 91 git add internal/version/version.go 92 git commit -s -m "chore: Update version.go for ${TAG}" 93 94 - name: Create tag 95 id: tag 96 run: | 97 # create new tag 98 git tag -a ${TAG} -m "Release ${TAG}" 99 100 # find latest tag sorted by semver ref 101 LATEST=$(git tag --sort=v:refname | tail -1) 102 103 # check whether the new tag is also the latest 104 if [[ $LATEST == $TAG ]]; then 105 echo "islatest::true >> $GITHUB_OUTPUT" 106 else 107 echo "islatest::false >> $GITHUB_OUTPUT" 108 fi 109 110 - name: Push changes and tag to release branch 111 if: ${{ !inputs.dryrun }} 112 run: | 113 git push --atomic --follow-tags origin ${{ github.ref }} 114 115 - name: Create RELEASE CHANGELOG 116 env: 117 IMAGE: quay.io/git-chglog/git-chglog 118 # https://quay.io/repository/git-chglog/git-chglog from tag v0.14.2 119 IMAGE_SHA: 998e89dab8dd8284cfff5f8cfb9e9af41fe3fcd4671f2e86a180e453c20959e3 120 run: | 121 # generate CHANGELOG for this Github release tag only 122 docker run --rm -v $PWD:/workdir ${IMAGE}@sha256:${IMAGE_SHA} -o RELEASE_CHANGELOG.md --sort semver --tag-filter-pattern '^v[0-9]+' ${TAG} 123 124 - name: Archive CHANGELOG 125 uses: actions/upload-artifact@v4 126 continue-on-error: true 127 with: 128 name: CHANGELOG 129 path: | 130 ./RELEASE_CHANGELOG.md 131 retention-days: 14 132 133 - name: Simulate Release without pushing Artifacts 134 if: ${{ inputs.dryrun }} 135 uses: goreleaser/goreleaser-action@v5 136 env: 137 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 138 with: 139 version: latest 140 args: release --snapshot --clean --release-notes RELEASE_CHANGELOG.md 141 142 143 - name: Create Release and build/push Artifacts 144 if: ${{ !inputs.dryrun }} 145 uses: goreleaser/goreleaser-action@v5 146 env: 147 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 148 with: 149 version: latest 150 args: release --clean --release-notes RELEASE_CHANGELOG.md # will push artefacts and container images 151 152 pull-request: 153 needs: release 154 name: Create CHANGELOG.md PR 155 runs-on: ubuntu-20.04 156 continue-on-error: true 157 # only update CHANGELOG for latest semver tag 158 if: ${{ !inputs.dryrun && needs.release.outputs.latesttag == 'true' }} 159 160 steps: 161 - name: Checkout 162 uses: actions/checkout@v4 163 with: 164 # for changelog 165 fetch-depth: 0 166 ref: "main" 167 168 - name: Create CHANGELOG.md commit 169 env: 170 IMAGE: quay.io/git-chglog/git-chglog 171 # https://quay.io/repository/git-chglog/git-chglog from tag v0.14.2 172 IMAGE_SHA: 998e89dab8dd8284cfff5f8cfb9e9af41fe3fcd4671f2e86a180e453c20959e3 173 run: | 174 # update CHANGELOG 175 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 176 177 - name: Create Pull Request 178 id: cpr 179 uses: peter-evans/create-pull-request@v6 180 with: 181 commit-message: "Update CHANGELOG for ${{ inputs.tag }}" 182 delete-branch: true 183 title: "Update CHANGELOG for ${{ inputs.tag }}" 184 signoff: true 185 draft: false 186 body: | 187 ### Update CHANGELOG.md for new release. 188 189 > **Note** 190 > 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. 191 192 - name: Pull Request Information 193 run: | 194 echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" 195 echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"