Repository navigation
CI Pull request #71 by patrostkowski #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copyright 2025 Patryk Rostkowski | |
| # | |
| # 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: CI | |
| run-name: > | |
| CI Pull request #${{ github.event.issue.number }} by ${{ github.actor }} | |
| on: | |
| issue_comment: | |
| types: [created] | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| if: > | |
| github.event.issue.pull_request && | |
| github.event.comment.body == '/ci' && | |
| contains(fromJson('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association) | |
| steps: | |
| - name: Fetch PR data | |
| id: pr | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const { owner, repo } = context.repo; | |
| const issue_number = context.payload.issue.number; | |
| const pr = await github.rest.pulls.get({ | |
| owner, | |
| repo, | |
| pull_number: issue_number, | |
| }); | |
| core.setOutput("head_repo", pr.data.head.repo.full_name); | |
| core.setOutput("head_sha", pr.data.head.sha); | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| repository: ${{ steps.pr.outputs.head_repo }} | |
| ref: ${{ steps.pr.outputs.head_sha }} | |
| fetch-depth: 0 | |
| - name: Setup Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Go test | |
| run: go test ./... | |
| - name: golangci-lint | |
| uses: golangci/golangci-lint-action@v8 | |
| with: | |
| args: --timeout=5m | |
| - name: Build binaries | |
| run: | | |
| go build ./cmd/controlplane-operator | |
| go build ./cmd/tesseractl | |
| comment: | |
| runs-on: ubuntu-latest | |
| needs: [test] | |
| if: ${{ always() }} | |
| permissions: | |
| issues: write | |
| pull-requests: read | |
| steps: | |
| - name: Fetch PR data | |
| id: pr | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const { owner, repo } = context.repo; | |
| const issue_number = context.payload.issue.number; | |
| const pr = await github.rest.pulls.get({ | |
| owner, | |
| repo, | |
| pull_number: issue_number, | |
| }); | |
| core.setOutput("head_sha", pr.data.head.sha); | |
| - name: Comment result on PR | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const owner = context.repo.owner; | |
| const repo = context.repo.repo; | |
| const issue_number = context.payload.issue.number; | |
| const status = "${{ needs.test.result }}"; | |
| const runUrl = `${context.serverUrl}/${owner}/${repo}/actions/runs/${context.runId}`; | |
| const sha = "${{ steps.pr.outputs.head_sha }}"; | |
| const emoji = status === "success" ? "✅" : (status === "cancelled" ? "🟨" : "❌"); | |
| const body = | |
| `${emoji} **CI ${status}**\n\n` + | |
| `Run: ${runUrl}\n` + | |
| `Commit: \`${sha}\``; | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number, | |
| body, | |
| }); | |