Skip to content

Use Artifact Registry #39

Use Artifact Registry

Use Artifact Registry #39

Workflow file for this run

name: ci
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
check-server:
name: check server
runs-on: ubuntu-latest
timeout-minutes: 10
env:
PACKAGE_BASE_PATH: "${{ github.workspace }}/pkg"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: ./pkg/go.mod
cache-dependency-path: ./pkg/go.sum
cache: true
- name: Run unit tests
run: make ci-test
check-front:
name: check front
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: front
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 21.7.0
- name: Build
run: npm ci && npm run build
- name: Upload dist
uses: actions/upload-artifact@v4
with:
name: front-dist-${{ github.sha }}
path: ./front/dist
if-no-files-found: error
retention-days: 1
if: github.ref == 'refs/heads/main'
release-server:
name: release server
runs-on: ubuntu-latest
timeout-minutes: 20
needs: [check-server, check-front]
permissions:
contents: read
id-token: write
pull-requests: write
env:
TF_VERSION: "1.4.6"
defaults:
run:
working-directory: deploy
steps:
- name: Checkout
uses: actions/checkout@v4
# Go
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: ./pkg/go.mod
cache-dependency-path: ./pkg/go.sum
cache: true
- run: make build before-deploy
working-directory: .
# GCP
- name: Authenticate Google Cloud
uses: google-github-actions/auth@v2
id: auth
with:
project_id: haraiai
workload_identity_provider: ${{ vars.GCLOUD_WORKFLOW_IDENTITY_PROVIDER }}
service_account: ${{ vars.GCLOUD_SERVICE_ACCOUNT }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
with:
version: ">= 363.0.0"
- run: gcloud info
# Terraform
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- id: init
run: terraform init -upgrade
- id: validate
run: terraform validate -no-color
- id: plan
if: github.event_name == 'pull_request'
run: terraform plan -no-color -input=false
continue-on-error: true
- uses: actions/github-script@v7
if: github.event_name == 'pull_request'
env:
PLAN: "${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`terraform\n
${process.env.PLAN}
\`\`\`
</details>
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- run: exit 1
if: steps.plan.outcome == 'failure'
- run: terraform apply -auto-approve -input=false
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
release-front:
name: release front
runs-on: ubuntu-latest
timeout-minutes: 20
if: github.ref == 'refs/heads/main'
needs: [check-server, check-front]
steps:
- uses: actions/download-artifact@v4
with:
name: front-dist-${{ github.sha }}
path: ./dist
- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@1
with:
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
projectName: haraiai
directory: ./dist
gitHubToken: ${{ secrets.GITHUB_TOKEN }}