mirror of
https://github.com/immich-app/static-pages.git
synced 2026-09-30 13:23:05 +08:00
263 lines
9.3 KiB
YAML
263 lines
9.3 KiB
YAML
name: Build
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
release:
|
|
types: [published]
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
tofu_version: '1.10.2'
|
|
tg_version: '0.83.0'
|
|
ENVIRONMENT: ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
|
|
|
|
jobs:
|
|
build-frontend:
|
|
name: Build Frontend
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
app_name: ['root', 'api', 'awesome', 'my', 'get', 'buy', 'datasets', 'futo-backups-survey']
|
|
include:
|
|
- app_name: futo-backups-survey
|
|
app_dir: futo-backups-survey.immich.app
|
|
|
|
defaults:
|
|
run:
|
|
working-directory: apps/${{ matrix.app_dir || format('{0}.immich.app', matrix.app_name) }}
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Setup pnpm
|
|
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
|
|
with:
|
|
node-version-file: './.nvmrc'
|
|
cache: 'pnpm'
|
|
cache-dependency-path: '**/pnpm-lock.yaml'
|
|
|
|
- name: Install
|
|
run: pnpm install
|
|
|
|
- name: Build
|
|
env:
|
|
PUBLIC_IMMICH_PAY_HOST: ${{ env.ENVIRONMENT == 'dev' && 'https://futopay-test.azurewebsites.net' || 'https://pay.futo.org' }}
|
|
PUBLIC_CF_TURNSTILE_SITE: ${{ secrets.CF_TURNSTILE_DEFAULT_INVISIBLE_SITE_KEY }}
|
|
run: pnpm build
|
|
|
|
- name: Upload build output
|
|
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
|
|
with:
|
|
name: build-frontend-output-${{ matrix.app_name }}
|
|
include-hidden-files: true
|
|
path: apps/${{ matrix.app_dir || format('{0}.immich.app', matrix.app_name) }}/${{ matrix.build_path || 'build' }}
|
|
retention-days: 1
|
|
|
|
build-backend:
|
|
name: Build Backend
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
app_name: ['datasets', 'futo-backups-survey']
|
|
include:
|
|
- app_name: futo-backups-survey
|
|
app_dir: futo-backups-survey.immich.app
|
|
|
|
defaults:
|
|
run:
|
|
working-directory: apps/${{ matrix.app_dir || format('{0}.immich.app', matrix.app_name) }}/backend
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Setup pnpm
|
|
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
|
|
with:
|
|
node-version-file: './.nvmrc'
|
|
cache: 'pnpm'
|
|
cache-dependency-path: '**/pnpm-lock.yaml'
|
|
|
|
- name: Run pnpm install
|
|
run: pnpm install
|
|
|
|
- name: Build backend
|
|
run: npx wrangler build
|
|
|
|
- name: Upload build output
|
|
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
|
|
with:
|
|
name: build-backend-output-${{ matrix.app_name }}
|
|
path: apps/${{ matrix.app_dir || format('{0}.immich.app', matrix.app_name) }}/backend/dist
|
|
retention-days: 1
|
|
|
|
deploy:
|
|
name: Deploy
|
|
runs-on: ubuntu-latest
|
|
needs: [build-frontend, build-backend]
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
app_name: ['root', 'api', 'awesome', 'my', 'get', 'buy', 'datasets', 'futo-backups-survey']
|
|
include:
|
|
- app_name: futo-backups-survey
|
|
app_dir: futo-backups-survey.immich.app
|
|
env:
|
|
TF_VAR_app_name: ${{ matrix.app_name }}
|
|
TF_VAR_stage: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || '' }}
|
|
TF_VAR_dist_dir: ${{ github.workspace }}/dist/backend
|
|
TF_VAR_migrations_dir: ${{ github.workspace }}/apps/${{ matrix.app_dir || format('{0}.immich.app', matrix.app_name) }}/backend/migrations
|
|
OP_SERVICE_ACCOUNT_TOKEN: ${{ github.ref == 'refs/heads/main' && secrets.OP_TF_PROD_ENV || secrets.OP_TF_DEV_ENV }}
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Get build artifact
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
with:
|
|
name: 'build-frontend-output-${{ matrix.app_name }}'
|
|
path: '${{ github.workspace }}/dist/frontend'
|
|
|
|
- name: Check if the app has a backend folder
|
|
id: check-backend
|
|
run: |
|
|
APP_DIR="${{ matrix.app_dir || format('{0}.immich.app', matrix.app_name) }}"
|
|
if [ -d "apps/${APP_DIR}/backend" ]; then
|
|
echo "has_backend=true" >> $GITHUB_ENV
|
|
else
|
|
echo "has_backend=false" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- name: Get backend build artifact
|
|
if: ${{ env.has_backend == 'true' }}
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
with:
|
|
name: 'build-backend-output-${{ matrix.app_name }}'
|
|
path: '${{ github.workspace }}/dist/backend'
|
|
|
|
- name: Install 1Password CLI
|
|
uses: 1password/install-cli-action@9a0c9dd934086b7ab1d90115d455bda1c53c2bdb # v2
|
|
|
|
- name: Install Terragrunt
|
|
uses: eLco/setup-terragrunt@2c5116f8979bb261072ef57c97ac026cd9c27434 # v1
|
|
with:
|
|
terragrunt_version: ${{ env.tg_version }}
|
|
|
|
- name: 'Install OpenTofu'
|
|
uses: opentofu/setup-opentofu@9d84900f3238fab8cd84ce47d658d25dd008be2f # v1
|
|
with:
|
|
tofu_version: ${{ env.tofu_version }}
|
|
tofu_wrapper: false
|
|
|
|
- name: Deploy All
|
|
working-directory: ${{ github.workspace }}/deployment
|
|
run: |
|
|
INCLUDE_DIRS=""
|
|
if [ "${{ env.has_backend }}" = "true" ]; then
|
|
INCLUDE_DIRS='**/workers/${{ matrix.app_name }}'
|
|
fi
|
|
|
|
QUEUE_ARGS=(--queue-include-dir='**/!(workers)/**')
|
|
if [ -n "$INCLUDE_DIRS" ]; then
|
|
QUEUE_ARGS+=(--queue-include-dir="$INCLUDE_DIRS")
|
|
fi
|
|
|
|
op run --env-file='.env' -- terragrunt run --all apply \
|
|
--non-interactive \
|
|
--parallelism 1 \
|
|
"${QUEUE_ARGS[@]}"
|
|
|
|
- name: Cloudflare Deploy Output
|
|
id: deploy-output
|
|
working-directory: ${{ github.workspace }}/deployment/modules/cloudflare/static-pages
|
|
run: |
|
|
echo "output=$(op run --no-masking --env-file='../../../.env' -- terragrunt output -json | jq -c .)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Publish Frontend to Cloudflare Pages
|
|
uses: cloudflare/pages-action@f0a1cd58cd66095dee69bfa18fa5efd1dde93bca # v1
|
|
with:
|
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN_PAGES_UPLOAD }}
|
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
projectName: ${{ fromJson(steps.deploy-output.outputs.output).pages_project_name.value }}
|
|
directory: 'dist/frontend'
|
|
branch: ${{ fromJson(steps.deploy-output.outputs.output).pages_branch.value }}
|
|
wranglerVersion: '3'
|
|
|
|
- name: Save preview URL
|
|
if: ${{ github.event_name == 'pull_request' }}
|
|
env:
|
|
APP_NAME: ${{ matrix.app_name }}
|
|
SUBDOMAIN: ${{ fromJson(steps.deploy-output.outputs.output).immich_subdomain.value }}
|
|
run: |
|
|
mkdir -p /tmp/preview-urls
|
|
echo "${APP_NAME}|${SUBDOMAIN}" > "/tmp/preview-urls/${APP_NAME}.txt"
|
|
|
|
- name: Upload preview URL
|
|
if: ${{ github.event_name == 'pull_request' }}
|
|
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
|
|
with:
|
|
name: preview-url-${{ matrix.app_name }}
|
|
path: /tmp/preview-urls/${{ matrix.app_name }}.txt
|
|
retention-days: 1
|
|
|
|
preview-comment:
|
|
name: Preview Comment
|
|
runs-on: ubuntu-latest
|
|
needs: [deploy]
|
|
if: ${{ !cancelled() && github.event_name == 'pull_request' }}
|
|
steps:
|
|
- name: Download all preview URLs
|
|
continue-on-error: true
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
with:
|
|
pattern: preview-url-*
|
|
path: /tmp/preview-urls
|
|
merge-multiple: true
|
|
|
|
- name: Build comment body
|
|
id: build-comment
|
|
env:
|
|
SHA: ${{ github.event.pull_request.head.sha }}
|
|
run: |
|
|
shopt -s nullglob
|
|
SHORT_SHA="${SHA:0:7}"
|
|
BODY="<!-- preview-urls -->"$'\n'
|
|
BODY+="### Preview Deployments ([${SHORT_SHA}](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commit/${SHA}))"$'\n\n'
|
|
BODY+="| App | Preview URL |"$'\n'
|
|
BODY+="|-----|-------------|"$'\n'
|
|
for file in /tmp/preview-urls/*.txt; do
|
|
IFS='|' read -r app_name subdomain < "$file"
|
|
BODY+="| ${app_name}.immich.app | [${subdomain}](https://${subdomain}) |"$'\n'
|
|
done
|
|
{
|
|
echo "body<<COMMENT_EOF"
|
|
echo "$BODY"
|
|
echo "COMMENT_EOF"
|
|
} >> $GITHUB_OUTPUT
|
|
|
|
- name: Comment
|
|
uses: actions-cool/maintain-one-comment@4b2dbf086015f892dcb5e8c1106f5fccd6c1476b # v3
|
|
with:
|
|
number: ${{ github.event.number }}
|
|
body: ${{ steps.build-comment.outputs.body }}
|
|
emojis: 'rocket'
|
|
body-include: '<!-- preview-urls -->'
|