|
| 1 | +name: PR |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [master] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: pr-${{ github.event.pull_request.number }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +jobs: |
| 12 | + goreleaser: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + env: |
| 15 | + DOCKER_REGISTRY: ${{ vars.DOCKER_REGISTRY || format('ghcr.io/{0}', github.repository_owner) }} |
| 16 | + DOCKER_REGISTRY_HOST: ${{ vars.DOCKER_REGISTRY_HOST || 'ghcr.io' }} |
| 17 | + permissions: |
| 18 | + contents: read |
| 19 | + pull-requests: write |
| 20 | + packages: write |
| 21 | + steps: |
| 22 | + - name: Prepare |
| 23 | + run: | |
| 24 | + repository=${{ github.repository }} |
| 25 | + echo "PROJECT_NAME=${repository#*/}" >> $GITHUB_ENV |
| 26 | +
|
| 27 | + - name: Checkout |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + - name: Login to Container registry |
| 33 | + if: github.actor != 'dependabot[bot]' |
| 34 | + uses: docker/login-action@v3 |
| 35 | + with: |
| 36 | + registry: ${{ env.DOCKER_REGISTRY_HOST }} |
| 37 | + username: ${{ github.actor }} |
| 38 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + |
| 40 | + - name: Set up Docker Buildx |
| 41 | + uses: docker/setup-buildx-action@v3 |
| 42 | + |
| 43 | + - uses: actions/setup-go@v6 |
| 44 | + with: |
| 45 | + go-version: stable |
| 46 | + |
| 47 | + - name: Run GoReleaser |
| 48 | + uses: goreleaser/goreleaser-action@v6 |
| 49 | + env: |
| 50 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 51 | + DOCKER_REGISTRY: ${{ env.DOCKER_REGISTRY }} |
| 52 | + with: |
| 53 | + distribution: goreleaser |
| 54 | + version: "~> v2" |
| 55 | + args: release --snapshot |
| 56 | + |
| 57 | + - name: Upload to S3 |
| 58 | + if: github.actor != 'dependabot[bot]' |
| 59 | + uses: capcom6/upload-s3-action@c4fae9e0868ea2a99ef8e9318e93821e84086955 # v2.0.0 |
| 60 | + env: |
| 61 | + AWS_REGION: ${{ secrets.AWS_REGION }} |
| 62 | + with: |
| 63 | + aws_key_id: ${{ secrets.AWS_KEY_ID }} |
| 64 | + aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}} |
| 65 | + aws_bucket: ${{ secrets.AWS_BUCKET }} |
| 66 | + endpoint: ${{ secrets.AWS_ENDPOINT }} |
| 67 | + source_files: | |
| 68 | + dist/${{ env.PROJECT_NAME }}_*.zip |
| 69 | + dist/${{ env.PROJECT_NAME }}_*.tar.gz |
| 70 | + destination_dir: ${{ github.repository }}/${{ github.event.pull_request.head.sha }} |
| 71 | + |
| 72 | + - name: Push images |
| 73 | + if: github.actor != 'dependabot[bot]' |
| 74 | + env: |
| 75 | + DOCKER_REGISTRY: ${{ env.DOCKER_REGISTRY }} |
| 76 | + PROJECT_NAME: ${{ env.PROJECT_NAME }} |
| 77 | + run: | |
| 78 | + docker tag ${{ env.DOCKER_REGISTRY }}/${{ env.PROJECT_NAME }}:latest-arm64 ${{ env.DOCKER_REGISTRY }}/${{ env.PROJECT_NAME }}:pr-${{ github.event.pull_request.number }}-arm64 |
| 79 | + docker tag ${{ env.DOCKER_REGISTRY }}/${{ env.PROJECT_NAME }}:latest-amd64 ${{ env.DOCKER_REGISTRY }}/${{ env.PROJECT_NAME }}:pr-${{ github.event.pull_request.number }}-amd64 |
| 80 | + docker push ${{ env.DOCKER_REGISTRY }}/${{ env.PROJECT_NAME }}:pr-${{ github.event.pull_request.number }}-arm64 |
| 81 | + docker push ${{ env.DOCKER_REGISTRY }}/${{ env.PROJECT_NAME }}:pr-${{ github.event.pull_request.number }}-amd64 |
| 82 | + docker manifest create ${{ env.DOCKER_REGISTRY }}/${{ env.PROJECT_NAME }}:pr-${{ github.event.pull_request.number }} \ |
| 83 | + ${{ env.DOCKER_REGISTRY }}/${{ env.PROJECT_NAME }}:pr-${{ github.event.pull_request.number }}-amd64 \ |
| 84 | + ${{ env.DOCKER_REGISTRY }}/${{ env.PROJECT_NAME }}:pr-${{ github.event.pull_request.number }}-arm64 |
| 85 | + docker manifest push ${{ env.DOCKER_REGISTRY }}/${{ env.PROJECT_NAME }}:pr-${{ github.event.pull_request.number }} |
| 86 | +
|
| 87 | + - name: Find Comment |
| 88 | + if: github.actor != 'dependabot[bot]' |
| 89 | + uses: peter-evans/find-comment@v3 |
| 90 | + id: fc |
| 91 | + with: |
| 92 | + issue-number: ${{ github.event.pull_request.number }} |
| 93 | + comment-author: "github-actions[bot]" |
| 94 | + body-includes: Pull request artifacts |
| 95 | + |
| 96 | + - name: Create or update comment |
| 97 | + if: github.actor != 'dependabot[bot]' |
| 98 | + uses: peter-evans/create-or-update-comment@v4 |
| 99 | + env: |
| 100 | + DOCKER_REGISTRY: ${{ env.DOCKER_REGISTRY }} |
| 101 | + PROJECT_NAME: ${{ env.PROJECT_NAME }} |
| 102 | + with: |
| 103 | + comment-id: ${{ steps.fc.outputs.comment-id }} |
| 104 | + issue-number: ${{ github.event.pull_request.number }} |
| 105 | + body: | |
| 106 | + ## 🤖 Pull request artifacts |
| 107 | +
|
| 108 | + | Platform | File | |
| 109 | + | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 110 | + | 🐳 Docker | [GitHub Container Registry](https://${{ env.DOCKER_REGISTRY }}/${{ env.PROJECT_NAME }}:pr-${{ github.event.pull_request.number }}) | |
| 111 | + | 🍎 Darwin arm64 | [${{ env.PROJECT_NAME }}_Darwin_arm64.tar.gz](https://${{ secrets.AWS_BUCKET }}/${{ github.repository }}/${{ github.event.pull_request.head.sha }}/${{ env.PROJECT_NAME }}_Darwin_arm64.tar.gz) | |
| 112 | + | 🍎 Darwin x86_64 | [${{ env.PROJECT_NAME }}_Darwin_x86_64.tar.gz](https://${{ secrets.AWS_BUCKET }}/${{ github.repository }}/${{ github.event.pull_request.head.sha }}/${{ env.PROJECT_NAME }}_Darwin_x86_64.tar.gz) | |
| 113 | + | 🐧 Linux arm64 | [${{ env.PROJECT_NAME }}_Linux_arm64.tar.gz](https://${{ secrets.AWS_BUCKET }}/${{ github.repository }}/${{ github.event.pull_request.head.sha }}/${{ env.PROJECT_NAME }}_Linux_arm64.tar.gz) | |
| 114 | + | 🐧 Linux i386 | [${{ env.PROJECT_NAME }}_Linux_i386.tar.gz](https://${{ secrets.AWS_BUCKET }}/${{ github.repository }}/${{ github.event.pull_request.head.sha }}/${{ env.PROJECT_NAME }}_Linux_i386.tar.gz) | |
| 115 | + | 🐧 Linux x86_64 | [${{ env.PROJECT_NAME }}_Linux_x86_64.tar.gz](https://${{ secrets.AWS_BUCKET }}/${{ github.repository }}/${{ github.event.pull_request.head.sha }}/${{ env.PROJECT_NAME }}_Linux_x86_64.tar.gz) | |
| 116 | + | 🪟 Windows arm64 | [${{ env.PROJECT_NAME }}_Windows_arm64.zip](https://${{ secrets.AWS_BUCKET }}/${{ github.repository }}/${{ github.event.pull_request.head.sha }}/${{ env.PROJECT_NAME }}_Windows_arm64.zip) | |
| 117 | + | 🪟 Windows i386 | [${{ env.PROJECT_NAME }}_Windows_i386.zip](https://${{ secrets.AWS_BUCKET }}/${{ github.repository }}/${{ github.event.pull_request.head.sha }}/${{ env.PROJECT_NAME }}_Windows_i386.zip) | |
| 118 | + | 🪟 Windows x86_64 | [${{ env.PROJECT_NAME }}_Windows_x86_64.zip](https://${{ secrets.AWS_BUCKET }}/${{ github.repository }}/${{ github.event.pull_request.head.sha }}/${{ env.PROJECT_NAME }}_Windows_x86_64.zip) | |
| 119 | +
|
| 120 | + edit-mode: replace |
0 commit comments