Build and Deploy #66
Workflow file for this run
This file contains 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 Deploy | |
on: | |
workflow_dispatch: | |
inputs: | |
deploy-frontend: | |
description: "Deploy Frontend" | |
default: false | |
type: boolean | |
deploy-backend: | |
description: "Deploy Backend" | |
default: false | |
type: boolean | |
update-data: | |
description: "Update Data" | |
default: false | |
type: boolean | |
push: | |
branches: | |
- main | |
jobs: | |
setup: | |
name: Deploy Setup | |
runs-on: ubuntu-latest | |
outputs: | |
frontend-changed: ${{ steps.changes.outputs.frontend-changed }} | |
data-changed: ${{ steps.changes.outputs.data-changed }} | |
backend-changed: ${{ steps.changes.outputs.backend-changed }} | |
steps: | |
- name: Checkout | |
uses: actions/[email protected] | |
- name: Detect Changes | |
id: changes | |
run: | | |
FRONTEND_DIFF=$(git diff --name-only HEAD~1 -- frontend/* | wc -l | xargs) | |
DATA_DIFF=$(git diff --name-only HEAD~1 -- data/* | wc -l | xargs) | |
BACKEND_DIFF=$(git diff --name-only HEAD~1 -- backend/* | wc -l | xargs) | |
if [[ "$FRONTEND_DIFF" == "1" ]]; then | |
echo "frontend-changed=true" >> $GITHUB_OUTPUT | |
fi | |
if [[ "$DATA_DIFF" == "1" ]]; then | |
echo "data-changed=true" >> $GITHUB_OUTPUT | |
fi | |
if [[ "$BACKEND_DIFF" == "1" ]]; then | |
echo "backend-changed=true" >> $GITHUB_OUTPUT | |
fi | |
build-frontend: | |
name: Build Frontend | |
if: ${{ needs.setup.outputs.frontend-changed == 'true' || inputs.deploy-frontend }} | |
needs: [setup] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/[email protected] | |
- name: Build Site | |
run: | | |
cd frontend | |
npm ci | |
echo "{}" > src/posts.json | |
npm run build | |
- name: Upload Site Artifact | |
uses: actions/[email protected] | |
with: | |
path: frontend/build | |
deploy-frontend: | |
name: Deploy Frontend | |
if: ${{ needs.setup.outputs.frontend-changed == 'true' || inputs.deploy-frontend }} | |
runs-on: ubuntu-latest | |
needs: | |
- setup | |
- build-frontend | |
permissions: | |
pages: write # to deploy to Pages | |
id-token: write # to verify the deployment originates from an appropriate source | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/[email protected] | |
build-n-deploy-data: | |
name: Build Data | |
if: ${{ needs.setup.outputs.data-changed == 'true' || inputs.update-data }} | |
needs: [setup] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/[email protected] | |
- name: Build data | |
working-directory: data | |
run: | | |
npm run build:posts | |
npm run build:rss | |
- name: Publish posts to R2 | |
uses: cloudflare/[email protected] | |
with: | |
apiToken: ${{ secrets.CF_API_KEY }} | |
accountId: ${{ secrets.CF_ACCOUNT }} | |
command: r2 object put flinnlab-blog/posts.json --file ./data/posts.json | |
- name: Publish RSS Feed to R2 | |
uses: cloudflare/[email protected] | |
with: | |
apiToken: ${{ secrets.CF_API_KEY }} | |
accountId: ${{ secrets.CF_ACCOUNT }} | |
command: r2 object put flinnlab-blog/rss.xml --file ./data/rss.xml | |
deploy-backend: | |
name: Deploy Backend | |
if: ${{ needs.setup.outputs.backend-changed == 'true' || inputs.deploy-backend }} | |
needs: [setup] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/[email protected] | |
- name: Deploy Backend | |
uses: cloudflare/[email protected] | |
with: | |
apiToken: ${{ secrets.CF_API_KEY }} | |
accountId: ${{ secrets.CF_ACCOUNT }} | |
workingDirectory: backend | |
command: deploy --env production |