|
| 1 | +name: pr-rc-build |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: [opened, synchronize, reopened] |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: read |
| 8 | + pull-requests: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + rc-build: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + rc_tag: ${{ steps.rc_tag.outputs.rc_tag }} |
| 15 | + version: ${{ steps.rc_tag.outputs.version }} |
| 16 | + steps: |
| 17 | + - name: Checkout repository |
| 18 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 19 | + |
| 20 | + - name: Generate RC tag |
| 21 | + id: rc_tag |
| 22 | + run: | |
| 23 | + VERSION=$(cat VERSION | tr -d '[:space:]') |
| 24 | + SHORT_SHA=$(echo "${{ github.event.pull_request.head.sha }}" | cut -c1-8) |
| 25 | + PR_NUMBER=${{ github.event.pull_request.number }} |
| 26 | + RC_TAG="${VERSION}-rc.${PR_NUMBER}.${SHORT_SHA}" |
| 27 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 28 | + echo "rc_tag=${RC_TAG}" >> $GITHUB_OUTPUT |
| 29 | + echo "RC tag: ${RC_TAG}" |
| 30 | +
|
| 31 | + - name: Install Go |
| 32 | + uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1 |
| 33 | + with: |
| 34 | + go-version-file: go.mod |
| 35 | + cache-dependency-path: "**/*.sum" |
| 36 | + |
| 37 | + - name: Install deb packages |
| 38 | + uses: awalsh128/cache-apt-pkgs-action@acb598e5ddbc6f68a970c5da0688d2f3a9f04d05 # v1.6.0 |
| 39 | + with: |
| 40 | + packages: protobuf-compiler |
| 41 | + version: 1.0 |
| 42 | + |
| 43 | + - name: Install go packages |
| 44 | + run: | |
| 45 | + go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28 |
| 46 | + go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2 |
| 47 | + export PATH="$PATH:$(go env GOPATH)/bin" |
| 48 | + go install github.com/swaggo/swag/cmd/swag@latest |
| 49 | +
|
| 50 | + - name: Build |
| 51 | + run: make build |
| 52 | + |
| 53 | + - name: Comment RC tag on PR |
| 54 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 55 | + with: |
| 56 | + script: | |
| 57 | + const rcTag = '${{ steps.rc_tag.outputs.rc_tag }}'; |
| 58 | + const version = '${{ steps.rc_tag.outputs.version }}'; |
| 59 | + const body = `### 🏗️ Release Candidate Build |
| 60 | +
|
| 61 | + **RC Tag:** \`${rcTag}\` |
| 62 | + **Target Release:** \`v${version}\` |
| 63 | + **Commit:** \`${{ github.event.pull_request.head.sha }}\` |
| 64 | +
|
| 65 | + #### Docker Images |
| 66 | + | Service | Image | |
| 67 | + |---------|-------| |
| 68 | + | apigw | \`docker.sunet.se/iam_vc/apigw:${rcTag}\` | |
| 69 | + | verifier | \`docker.sunet.se/iam_vc/verifier:${rcTag}\` | |
| 70 | + | registry | \`docker.sunet.se/iam_vc/registry:${rcTag}\` | |
| 71 | + | mockas | \`docker.sunet.se/iam_vc/mockas:${rcTag}\` | |
| 72 | + | issuer | \`docker.sunet.se/iam_vc/issuer:${rcTag}\` | |
| 73 | + | ui | \`docker.sunet.se/iam_vc/ui:${rcTag}\` | |
| 74 | +
|
| 75 | + > Deploy with: \`VERSION=${rcTag} docker compose pull\``; |
| 76 | +
|
| 77 | + // Find and update existing RC comment or create new one |
| 78 | + const { data: comments } = await github.rest.issues.listComments({ |
| 79 | + owner: context.repo.owner, |
| 80 | + repo: context.repo.repo, |
| 81 | + issue_number: context.issue.number, |
| 82 | + }); |
| 83 | + const botComment = comments.find(c => |
| 84 | + c.user.type === 'Bot' && c.body.includes('Release Candidate Build') |
| 85 | + ); |
| 86 | + if (botComment) { |
| 87 | + await github.rest.issues.updateComment({ |
| 88 | + owner: context.repo.owner, |
| 89 | + repo: context.repo.repo, |
| 90 | + comment_id: botComment.id, |
| 91 | + body: body, |
| 92 | + }); |
| 93 | + } else { |
| 94 | + await github.rest.issues.createComment({ |
| 95 | + owner: context.repo.owner, |
| 96 | + repo: context.repo.repo, |
| 97 | + issue_number: context.issue.number, |
| 98 | + body: body, |
| 99 | + }); |
| 100 | + } |
0 commit comments