Files
services/.github/workflows/build.yml
T

142 lines
4.8 KiB
YAML

name: Build
on:
push:
branches: [main]
pull_request:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
TG_NON_INTERACTIVE: 'true'
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Setup pnpm
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
- name: Setup Node
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version-file: '.nvmrc'
- name: Run pnpm install
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm build
- name: Upload build output
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: build-output
path: 'dist'
retention-days: 7
deploy-dev:
name: Deploy (dev)
runs-on: ubuntu-latest
needs: [build]
env:
ENVIRONMENT: dev
TF_VAR_stage: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || '' }}
TF_VAR_dist_dir: ${{ github.workspace }}/dist
TF_VAR_migrations_dir: ${{ github.workspace }}/apps/version/migrations
OP_SERVICE_ACCOUNT_TOKEN: ${{ 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.0.1
with:
name: 'build-output'
path: '${{ github.workspace }}/dist'
- name: Install 1Password CLI
uses: 1password/install-cli-action@8d006a0d0a4fd505af7f7ce589e7f768385ff5e4 # v3.0.0
- name: Setup Mise
uses: immich-app/devtools/actions/use-mise@697a75e2c3186d3c037c2c159855cf2d566542ba # use-mise-action-0.0.1
- name: Deploy All
working-directory: ${{ github.workspace }}/deployment
run: mise run tf:apply
- name: Collect preview URLs
if: ${{ github.event_name == 'pull_request' }}
id: preview-urls
working-directory: ${{ github.workspace }}/deployment
run: |
BODY="<!-- preview-urls -->"$'\n'
SHORT_SHA="${{ github.event.pull_request.head.sha }}"
SHORT_SHA="${SHORT_SHA:0:7}"
BODY+="### Preview Deployments ([${SHORT_SHA}](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commit/${{ github.event.pull_request.head.sha }}))"$'\n\n'
BODY+="| Worker | Preview URL |"$'\n'
BODY+="|--------|-------------|"$'\n'
for dir in modules/cloudflare/workers/*/; do
worker_name=$(basename "$dir")
cd "${{ github.workspace }}/deployment/${dir}"
url=$(mise run tg output -raw preview_url 2>/dev/null) || true
cd "${{ github.workspace }}/deployment"
if [ -n "$url" ]; then
BODY+="| ${worker_name} | [${url}](${url}) |"$'\n'
fi
done
{
echo "body<<COMMENT_EOF"
echo "$BODY"
echo "COMMENT_EOF"
} >> $GITHUB_OUTPUT
- name: Comment preview URLs
if: ${{ github.event_name == 'pull_request' }}
uses: actions-cool/maintain-one-comment@772214ac4bff3c578c76eed4ac19d08dc787c050 # v3.2.1
with:
number: ${{ github.event.number }}
body: ${{ steps.preview-urls.outputs.body }}
emojis: 'rocket'
body-include: '<!-- preview-urls -->'
deploy-prod:
name: Deploy (prod)
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: [build]
env:
ENVIRONMENT: prod
TF_VAR_stage: ''
TF_VAR_dist_dir: ${{ github.workspace }}/dist
TF_VAR_migrations_dir: ${{ github.workspace }}/apps/version/migrations
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_TF_PROD_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.0.1
with:
name: 'build-output'
path: '${{ github.workspace }}/dist'
- name: Install 1Password CLI
uses: 1password/install-cli-action@8d006a0d0a4fd505af7f7ce589e7f768385ff5e4 # v3.0.0
- name: Setup Mise
uses: immich-app/devtools/actions/use-mise@697a75e2c3186d3c037c2c159855cf2d566542ba # use-mise-action-0.0.1
- name: Deploy All
working-directory: ${{ github.workspace }}/deployment
run: mise run tf:apply