From 75986f57bc9088ccb633aca1db8ad86e4b1dfc8c Mon Sep 17 00:00:00 2001 From: PoisonPhang <17688291+PoisonPhang@users.noreply.github.com> Date: Wed, 28 Aug 2024 11:48:14 -0500 Subject: [PATCH] feat(ci): use garnix cache instead of nixbuild --- .github/workflows/deploy-explorer.yml | 103 +++++++++++++++++++------- 1 file changed, 75 insertions(+), 28 deletions(-) diff --git a/.github/workflows/deploy-explorer.yml b/.github/workflows/deploy-explorer.yml index 490b1c4fab..58684f71df 100644 --- a/.github/workflows/deploy-explorer.yml +++ b/.github/workflows/deploy-explorer.yml @@ -4,6 +4,7 @@ on: push: branches: - master + pull_request: workflow_dispatch: concurrency: @@ -14,37 +15,86 @@ env: NODE_OPTIONS: '--no-warnings' jobs: - build: + garnix: + name: Wait on Garnix CI runs-on: ubuntu-latest + steps: + - name: Wait on Garnix CI Check Suite + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + REF: ${{ github.head_ref }} + run: | + 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: [garnix] permissions: contents: read + pull-requests: write + env: + npm_config_yes: true + environment: 'app-preview' + if: github.event_name == 'pull_request' 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 explorer + - uses: nixbuild/nix-quick-install-action@v28 + - name: Fetch from Cache run: | - touch build.json - nix build .#packages.x86_64-linux.explorer \ - --print-build-logs \ - --eval-store auto \ - --store ssh-ng://eu.nixbuild.net \ - --builders "" --max-jobs 2 \ - --show-trace \ - --json + nix develop + nix build .#explorer + - name: '[preview] 🔶 Publish to Cloudflare Pages' + env: + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_WORKERS_API_TOKEN }} + run: npx --yes wrangler@latest pages --project-name="app" deploy result >> /tmp/app_deploy.txt + - name: Set Deploy Output + run: | + { + echo 'DEPLOY_OUTPUT<> $GITHUB_ENV + - name: Comment Site Deploy Results + uses: thollander/actions-comment-pull-request@v2 + with: + message: | + # App 🤌 + ${{ env.DEPLOY_OUTPUT }} + + **${{ env.LAST_UPDATED_AT }}** + comment_tag: deploy-app-preview-result deploy-production: runs-on: 'ubuntu-latest' - needs: [ build ] + needs: [garnix] env: npm_config_yes: true environment: 'explorer-production' @@ -53,14 +103,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.explorer` --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 .#explorer - name: '[production] 🔶 Publish to Cloudflare Pages' env: CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}