# Copyright The ORAS Authors. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. name: release on: pull_request: types: [closed] branches: - v2 jobs: release: if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/') && github.event.pull_request.head.repo.full_name == github.repository runs-on: ubuntu-latest permissions: contents: write steps: - name: Checkout uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: fetch-depth: 0 ref: ${{ github.event.pull_request.merge_commit_sha }} - name: Set up Go uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0 with: go-version-file: go.mod check-latest: true - name: Extract version from branch name id: version run: | BRANCH="${{ github.head_ref }}" VERSION="${BRANCH#release/}" echo "version=$VERSION" >> $GITHUB_OUTPUT - name: Validate semantic version run: | VERSION="${{ steps.version.outputs.version }}" if ! [[ "$VERSION" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(alpha|beta|rc)\.[0-9]+)?$ ]]; then echo "Error: '$VERSION' does not follow semantic versioning" echo "Expected: vX.Y.Z or vX.Y.Z-(alpha|beta|rc).N" exit 1 fi - name: Create and push tag run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git tag ${{ steps.version.outputs.version }} ${{ github.event.pull_request.merge_commit_sha }} git push origin ${{ steps.version.outputs.version }} - name: Write release notes from PR body env: NOTES: ${{ github.event.pull_request.body }} run: printf '%s\n' "$NOTES" > /tmp/release-notes.md - name: Run GoReleaser uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0 with: version: latest args: release --clean --release-notes /tmp/release-notes.md env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}