Skip to content

Update Astro template (#35) #30

Update Astro template (#35)

Update Astro template (#35) #30

Workflow file for this run

name: Deploy CD
# GitHub variables:
# - VERSION_TAG
# - ASTRO_SITE_URL
# - ASTRO_BASE_PATH
# - ASTRO_ASSETS_PREFIX
# GitHub secrets:
# - CONFIG_PROD (optional)
on:
# Run on push on production branches
push:
branches:
# Production
- main
paths:
# CI/CD files
- '.github/workflows/deploy.yml'
- 'docker-compose.yml'
- 'docker-compose.cicd.yml'
- '.env'
# Application files
- 'app/**'
# Run on manual triggers
workflow_dispatch:
# Set default GITHUB_TOKEN permissions for the workflow
permissions:
contents: read
# Set workflow concurrency rules
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs:
# Build job
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 20
# Only run if:
# - Deploys are not disabled
if: |
vars.CI_DISABLE_DEPLOYS != 'true'
steps:
# Initialization steps
- name: Checkout
uses: actions/checkout@v6
# Dependency steps
- name: Install jq
run: |
# apt-get install jq
sudo apt-get -q update
sudo apt-get -qy install --no-install-recommends jq
# Preparation steps
- name: Load app config in environment
env:
CONFIG_PROD: ${{ secrets.CONFIG_PROD }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_SHA: ${{ github.sha }}
GITHUB_REF_NAME: ${{ github.ref_name }}
GITHUB_VARS: ${{ toJson(vars) }}
run: |
# Load app config in environment
# Load shell functions to load app config variables
. ./.github/workflows/scripts/load_app_config_functions.sh
echo '::group::Load app config variables'
# Deployment
load_var 'GITHUB_REPOSITORY_URL' 'false' "https://github.com/${GITHUB_REPOSITORY}"
load_var 'GITHUB_SHA' 'false' "${GITHUB_SHA}"
load_var 'VERSION_TAG' 'true' "${GITHUB_REF_NAME}"
# Astro
load_var 'ASTRO_SITE_URL' 'true'
load_var 'ASTRO_BASE_PATH' 'true'
load_var 'ASTRO_ASSETS_PREFIX' 'true'
# Application (app env vars)
# (Load env vars for your application here.)
echo '::endgroup::'
# Execution steps
- name: Download FluffEvent association documents
run: |
# download-documents.sh ./app
sh ./cicd/download-documents.sh ./app
- name: Pull dependencies
run: |
# docker compose pull --ignore-buildable
echo '::group::Pull details'
docker compose \
-f ./docker-compose.yml -f ./docker-compose.cicd.yml \
--env-file .env \
pull --ignore-buildable
echo '::endgroup::'
- name: Build for production
env:
# Build
BUILD_CHECK: 'false' # Skip type checks
# Deployment
GITHUB_REPOSITORY_URL: ${{ env.GITHUB_REPOSITORY_URL }}
GITHUB_SHA: ${{ env.GITHUB_SHA }}
VERSION_TAG: ${{ env.VERSION_TAG }}
# Astro
ASTRO_SITE_URL: ${{ env.ASTRO_SITE_URL }}
ASTRO_BASE_PATH: ${{ env.ASTRO_BASE_PATH }}
ASTRO_ASSETS_PREFIX: ${{ env.ASTRO_ASSETS_PREFIX }}
# Application (app env vars)
# (Add env vars for your application here.)
run: |
# docker compose build
echo '::group::Build details'
export DOCKER_UID="$(id -u)"
docker compose \
-f ./docker-compose.yml -f ./docker-compose.cicd.yml \
--env-file .env \
build
echo '::endgroup::'
- name: Copy application files
run: |
# docker compose up
echo '::group::Run details'
export DOCKER_UID="$(id -u)"
docker compose \
-f ./docker-compose.yml -f ./docker-compose.cicd.yml \
--env-file .env \
up
echo '::endgroup::'
- name: Upload GitHub Pages artifact
uses: actions/upload-pages-artifact@v4
with:
path: ./app/dist
# Deploy job
deploy:
name: Deploy
runs-on: ubuntu-latest
timeout-minutes: 10
# Job dependencies
needs:
- build
# Set GITHUB_TOKEN permissions for the job
permissions:
actions: write
id-token: write
pages: write
# Set deployment environment
environment:
name: production
url: ${{ steps.deployment.outputs.page_url }}
steps:
# Execution steps
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v5
- name: Delete GitHub Pages artifact
uses: actions/github-script@v8
env:
GITHUB_RUN_ID: ${{ github.run_id }}
ARTIFACT_PATTERN: '^github-pages$'
with:
script: |
const runId = process.env.GITHUB_RUN_ID;
const artifactPattern = new RegExp(process.env.ARTIFACT_PATTERN);
const owner = context.repo.owner;
const repo = context.repo.repo;
core.info(`Listing artifacts for run '${runId}' in '${owner}/${repo}'...`);
const res = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: runId,
});
const artifacts = res.data?.artifacts || [];
if (artifacts.length <= 0) {
core.info('No artifacts found.');
return;
}
const requiredArtifacts = artifacts.filter(a => artifactPattern.test(a.name));
if (requiredArtifacts.length <= 0) {
core.info('Required artifact(s) not found.');
return;
}
for (const artifact of requiredArtifacts) {
core.info(`Deleting artifact '${artifact.name}' (${artifact.id})...`);
await github.rest.actions.deleteArtifact({
owner,
repo,
artifact_id: artifact.id,
});
}
core.info('Done.');