Skip to content

Commit

Permalink
👷 Pre build steps and new pull requests CI
Browse files Browse the repository at this point in the history
  • Loading branch information
perdy committed Oct 26, 2023
1 parent bee50ad commit b3787a0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 26 deletions.
28 changes: 3 additions & 25 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- master
pull_request:

jobs:
terraform:
Expand Down Expand Up @@ -32,6 +31,9 @@ jobs:
- name: Build
id: build
run: npm run build
- name: List building output
id: list-output
run: ls -l out
- name: Clear bucket
id: clear
run: gcloud storage rm -c gs://${{ secrets.GCP_STORAGE_BUCKET_NAME }}/** || true
Expand All @@ -41,27 +43,3 @@ jobs:
- name: Update permissions
id: permissions
run: gcloud storage objects update -r gs://${{ secrets.GCP_STORAGE_BUCKET_NAME }}/* --add-acl-grant=entity=AllUsers,role=READER
- name: Update Pull Request
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: ${{ steps.plan.outputs.stdout }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Steps
| Step | Status |
| --------------------- | ------------------------------------------------------------ |
| 📦 Build and export | ${{ steps.build.outcome == 'success' && '✔' || '❌' }} |
| 🧹 Clear bucket | ${{ steps.clear.outcome == 'success' && '✔' || '❌' }} |
| 🚀 Deploy | ${{ steps.deploy.outcome == 'success' && '✔' || '❌' }} |
| 🛂 Update permissions | ${{ steps.permissions.outcome == 'success' && '✔' || '❌' }} |
*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
})
61 changes: 61 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: 'Test'

on:
pull_request:

jobs:
terraform:
name: 'Test'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Authenticate to GCP
id: auth
uses: google-github-actions/auth@v1
with:
token_format: access_token
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
- name: Install dependencies
id: deps
run: npm ci
- name: Build
id: build
run: npm run build
- name: List building output
id: list-output
run: ls -l out
- name: Clear bucket
id: clear
run: gcloud storage rm -c gs://${{ secrets.GCP_STORAGE_BUCKET_NAME }}/** || true
- name: Deploy
id: deploy
run: gcloud storage cp -c -r out/* gs://${{ secrets.GCP_STORAGE_BUCKET_NAME }}
- name: Update permissions
id: permissions
run: gcloud storage objects update -r gs://${{ secrets.GCP_STORAGE_BUCKET_NAME }}/* --add-acl-grant=entity=AllUsers,role=READER
- name: Update Pull Request
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Steps
| Step | Status |
| --------------------- | ------------------------------------------------------------ |
| 📦 Build and export | ${{ steps.build.outcome == 'success' && '✔' || '❌' }} |
*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
})
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"scripts": {
"start": "npm run dev",
"dev": "next",
"build": "contentlayer build && next build",
"prebuild": "contentlayer build",
"build": "next build",
"postbuild": "next-sitemap",
"serve": "next start",
"lint": "next lint",
Expand Down

0 comments on commit b3787a0

Please sign in to comment.