Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ci): provide backup sha when using garnix deploy #2869

Merged
merged 6 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 55 additions & 65 deletions .github/workflows/deploy-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,48 @@ concurrency:
cancel-in-progress: true

env:
NIX_VERSION: nix-2.13.2
NIXPKGS_CHANNEL: nixos-22.11
NODE_OPTIONS: '--no-warnings'
ACTIONS_RUNNER_DEBUG: true
ASTRO_TELEMETRY_DISABLED: true

jobs:
build:
runs-on: ['ubuntu-latest']
permissions:
contents: read
garnix:
name: Wait on Garnix CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
lfs: true
- uses: nixbuild/nix-quick-install-action@v26
with:
nix_on_tmpfs: false
nix_conf: |
experimental-features = nix-command flakes
access-tokens = ${{ secrets.GITHUB_TOKEN }}
- uses: nixbuild/nixbuild-action@812f1ab2b51842b0d44b9b79574611502d6940a0
with:
nixbuild_token: ${{secrets.nixbuild_token}}
- name: Build app
- name: Wait on Garnix CI Check Suite
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
REF: ${{ github.head_ref || github.sha }}
run: |
touch build.json
nix build .#packages.x86_64-linux.app \
--print-build-logs \
--eval-store auto \
--store ssh-ng://eu.nixbuild.net \
--builders "" --max-jobs 2 \
--show-trace \
--json
sleep 15

status=''

while [[ $status != 'completed' ]]; do
check_suites=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/$REPO/commits/$REF/check-suites")

status=$(echo "$check_suites" | jq -r '.check_suites | .[] | select(.app.name == "Garnix CI") | .status')
sleep 15
done
conclusion=$(echo "$check_suites" | jq -r '.check_suites | .[] | select(.app.name == "Garnix CI") | .conclusion')
case "$conclusion" in
failure | timed_out | action_required | stale | startup_failure)
echo "ERROR: Garnix CI concluded with $conclusion"
exit 1
;;
*)
echo "INFO: Garnix CI concluded with $conclusion"
;;
esac

deploy-preview:
runs-on: ['ubuntu-latest']
needs: [build]
needs: [garnix]
permissions:
contents: read
pull-requests: write
Expand All @@ -66,15 +70,11 @@ jobs:
- uses: actions/checkout@v4
with:
lfs: true
- uses: nixbuild/nix-quick-install-action@v26
- uses: nixbuild/nixbuild-action@812f1ab2b51842b0d44b9b79574611502d6940a0
with:
nixbuild_token: ${{ secrets.nixbuild_token }}
- run: mkdir dump
- run: nix copy --to file://`pwd`/dump --from ssh-ng://eu.nixbuild.net `nix eval --raw .#packages.x86_64-linux.app` --extra-experimental-features nix-command
- run: cat dump/nar/*.nar.xz | xz -dc | nix-store --restore result

# create preview deployment when trigger is pull_request, then post preview deployment url as a pr comment
- uses: nixbuild/nix-quick-install-action@v28
- name: Fetch from Cache
run: |
nix develop
nix build .#app
- name: '[preview] 🔶 Publish to Cloudflare Pages'
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
Expand All @@ -101,23 +101,19 @@ jobs:

deploy-manual:
runs-on: ['ubuntu-latest']
needs: [build]
needs: [garnix]
env:
npm_config_yes: true
if: github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v4
with:
lfs: true
- uses: nixbuild/nix-quick-install-action@v26
- uses: nixbuild/nixbuild-action@812f1ab2b51842b0d44b9b79574611502d6940a0
with:
nixbuild_token: ${{ secrets.nixbuild_token }}
- run: mkdir dump
- run: nix copy --to file://`pwd`/dump --from ssh-ng://eu.nixbuild.net `nix eval --raw .#packages.x86_64-linux.app` --extra-experimental-features nix-command
- run: cat dump/nar/*.nar.xz | xz -dc | nix-store --restore result

# create preview deployment when trigger is workflow_dispatch && branch is not main
- uses: nixbuild/nix-quick-install-action@v28
- name: Fetch from Cache
run: |
nix develop
nix build .#app
- name: '[workflow-dispatch] 🔶 Publish to Cloudflare Pages'
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
Expand All @@ -126,7 +122,7 @@ jobs:

deploy-staging:
runs-on: ['ubuntu-latest']
needs: [build]
needs: [garnix]
env:
npm_config_yes: true
environment: 'app-staging'
Expand All @@ -135,14 +131,11 @@ jobs:
- uses: actions/checkout@v4
with:
lfs: true
- uses: nixbuild/nix-quick-install-action@v26
- uses: nixbuild/nixbuild-action@812f1ab2b51842b0d44b9b79574611502d6940a0
with:
nixbuild_token: ${{ secrets.nixbuild_token }}
- run: mkdir dump
- run: nix copy --to file://`pwd`/dump --from ssh-ng://eu.nixbuild.net `nix eval --raw .#packages.x86_64-linux.app` --extra-experimental-features nix-command
- run: cat dump/nar/*.nar.xz | xz -dc | nix-store --restore result

- uses: nixbuild/nix-quick-install-action@v28
- name: Fetch from Cache
run: |
nix develop
nix build .#app
- name: '[staging] 🔶 Publish to Cloudflare Pages'
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
Expand All @@ -151,7 +144,7 @@ jobs:

deploy-production:
runs-on: ['ubuntu-latest']
needs: [build]
needs: [garnix]
env:
npm_config_yes: true
environment: 'app-production'
Expand All @@ -160,14 +153,11 @@ jobs:
- uses: actions/checkout@v4
with:
lfs: true
- uses: nixbuild/nix-quick-install-action@v26
- uses: nixbuild/nixbuild-action@812f1ab2b51842b0d44b9b79574611502d6940a0
with:
nixbuild_token: ${{ secrets.nixbuild_token }}
- run: mkdir dump
- run: nix copy --to file://`pwd`/dump --from ssh-ng://eu.nixbuild.net `nix eval --raw .#packages.x86_64-linux.app` --extra-experimental-features nix-command
- run: cat dump/nar/*.nar.xz | xz -dc | nix-store --restore result

- uses: nixbuild/nix-quick-install-action@v28
- name: Fetch from Cache
run: |
nix develop
nix build .#app
- name: '[production] 🔶 Publish to Cloudflare Pages'
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
Expand Down
1 change: 1 addition & 0 deletions app/app.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
buildInputs = combinedDeps;
installPhase = ''
mkdir -p $out
echo "force rebuild"
cp -r ./build/* $out
'';
doDist = false;
Expand Down