Feature/weekly release workflow #36
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
| name: Build and Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*.*.*' | |
| # Allow manual trigger by commenting on a PR with the command `/run-release`. | |
| # When triggered this way, VERSION will be set to: dev-[PR-number]-<timestamp> | |
| issue_comment: | |
| types: [created] | |
| jobs: | |
| build-package: | |
| runs-on: ubuntu-latest | |
| # Only run on tag push, or when a PR comment containing `/run-release` was created. | |
| if: > | |
| github.event_name == 'push' || | |
| (github.event_name == 'issue_comment' && startsWith(github.event.comment.body, '/run-release') && github.event.issue.pull_request) | |
| permissions: | |
| id-token: write | |
| contents: write | |
| issues: write | |
| outputs: | |
| version: ${{ steps.set-version.outputs.version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: 'go.mod' | |
| cache: true | |
| - name: Download dependencies | |
| run: go mod download | |
| - id: set-version | |
| name: Set VERSION | |
| run: | | |
| if [ "${{ github.event_name }}" = "issue_comment" ]; then | |
| PR_NUMBER=${{ github.event.issue.number }} | |
| TS=$(date -u +%Y%m%d%H%M%S) | |
| echo "version=dev-${PR_NUMBER}-${TS}" >> $GITHUB_OUTPUT | |
| echo "VERSION=dev-${PR_NUMBER}-${TS}" >> $GITHUB_ENV | |
| else | |
| echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT | |
| echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV | |
| fi | |
| - name: Build release | |
| run: make release | |
| env: | |
| VERSION: ${{ env.VERSION }} | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-bin | |
| path: bin/* | |
| packer-images: | |
| needs: build-package | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS credentials (OIDC) | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_ROLE_ARN }} | |
| aws-region: us-east-1 | |
| - id: gcp_auth | |
| name: Authenticate to GCP | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| token_format: 'access_token' | |
| workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} | |
| service_account: ${{ secrets.GCP_SERVICE_ACCOUNT_EMAIL }} | |
| - name: Setup gcloud | |
| uses: google-github-actions/setup-gcloud@v2 | |
| with: | |
| project_id: ${{ secrets.GCP_PROJECT_ID }} | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v5 | |
| with: | |
| name: release-bin | |
| path: ./bin | |
| - name: Upload to corresponding buckets | |
| run: | | |
| gsutil cp ./bin/velda-${{ needs.build-package.outputs.version }}-linux-amd64 gs://velda-release/velda-${{ needs.build-package.outputs.version }}-linux-amd64 | |
| aws s3 cp ./bin/velda-${{ needs.build-package.outputs.version }}-linux-amd64 s3://velda-release/velda-${{ needs.build-package.outputs.version }}-linux-amd64 | |
| - name: Install packer | |
| uses: hashicorp/setup-packer@v3 | |
| with: | |
| version: 1.14.1 | |
| - name: Initialize Packer | |
| run: packer init packer | |
| - name: Build images | |
| run: exec packer build -var="version=${{ needs.build-package.outputs.version }}" -var="gce_project_id=${{ secrets.GCP_PROJECT_ID }}" -var="docker_password=${{ secrets.DOCKER_PASSWORD }}" -var-file=packer/prod.pkrvars.hcl packer | |
| - name: Update permissions | |
| run: make -C packer update_permission | |
| env: | |
| VERSION: ${{ needs.build-package.outputs.version }} | |
| create-release: | |
| if: github.event_name == 'push' | |
| needs: [build-package, packer-images] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v5 | |
| with: | |
| name: release-bin | |
| path: ./bin | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: | | |
| bin/* | |
| tag_name: ${{ needs.build-package.outputs.version }} | |
| name: Release ${{ needs.build-package.outputs.version }} | |
| body: | | |
| **Tag:** ${{ needs.build-package.outputs.version }} | |
| **Commit:** ${{ github.sha }} | |
| draft: true | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |