Debian Codegraph @

.github/workflows/release.yml

raw
1 # Copyright The ORAS Authors.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
5 #
6 # http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 name: release
15
16 on:
17 pull_request:
18 types: [closed]
19 branches:
20 - v2
21
22 jobs:
23 release:
24 if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/') && github.event.pull_request.head.repo.full_name == github.repository
25 runs-on: ubuntu-latest
26 permissions:
27 contents: write
28 steps:
29 - name: Checkout
30 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
31 with:
32 fetch-depth: 0
33 ref: ${{ github.event.pull_request.merge_commit_sha }}
34
35 - name: Set up Go
36 uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
37 with:
38 go-version-file: go.mod
39 check-latest: true
40
41 - name: Extract version from branch name
42 id: version
43 run: |
44 BRANCH="${{ github.head_ref }}"
45 VERSION="${BRANCH#release/}"
46 echo "version=$VERSION" >> $GITHUB_OUTPUT
47
48 - name: Validate semantic version
49 run: |
50 VERSION="${{ steps.version.outputs.version }}"
51 if ! [[ "$VERSION" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(alpha|beta|rc)\.[0-9]+)?$ ]]; then
52 echo "Error: '$VERSION' does not follow semantic versioning"
53 echo "Expected: vX.Y.Z or vX.Y.Z-(alpha|beta|rc).N"
54 exit 1
55 fi
56
57 - name: Create and push tag
58 run: |
59 git config user.name "github-actions[bot]"
60 git config user.email "github-actions[bot]@users.noreply.github.com"
61 git tag ${{ steps.version.outputs.version }} ${{ github.event.pull_request.merge_commit_sha }}
62 git push origin ${{ steps.version.outputs.version }}
63
64 - name: Write release notes from PR body
65 env:
66 NOTES: ${{ github.event.pull_request.body }}
67 run: printf '%s\n' "$NOTES" > /tmp/release-notes.md
68
69 - name: Run GoReleaser
70 uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
71 with:
72 version: latest
73 args: release --clean --release-notes /tmp/release-notes.md
74 env:
75 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}