From 5ec212f3df056da15ce8df3b79eecbdeb73849a2 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Thu, 12 Jan 2023 13:11:15 +0000 Subject: [PATCH] fix commit hash setting --- .github/workflows/deploy.yml | 11 ++++++----- frontend/src/routes/(frontend)/layout.tsx | 3 ++- frontend/vite.config.ts | 3 +-- package.json | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 97e41e3..260b591 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,7 +1,7 @@ name: Deploy on: push: - branches: + branches: - main repository_dispatch: jobs: @@ -76,9 +76,9 @@ jobs: - name: retrieve Zero Trust organization run: | - auth_domain=$(curl https://api.cloudflare.com/client/v4/accounts/${{ secrets.CF_ACCOUNT_ID }}/access/organizations \ - -H 'Authorization: Bearer ${{ secrets.CF_API_TOKEN }}' | jq -r '.result.auth_domain') - printf "auth_domain=$auth_domain" >> $GITHUB_ENV + auth_domain=$(curl https://api.cloudflare.com/client/v4/accounts/${{ secrets.CF_ACCOUNT_ID }}/access/organizations \ + -H 'Authorization: Bearer ${{ secrets.CF_API_TOKEN }}' | jq -r '.result.auth_domain') + printf "auth_domain=$auth_domain" >> $GITHUB_ENV - name: retrieve Terraform state KV namespace uses: cloudflare/wrangler-action@2.0.0 @@ -161,7 +161,7 @@ jobs: env: CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} if: ${{ env.tfstate_kv == '' }} - + - name: store VAPID keys state uses: cloudflare/wrangler-action@2.0.0 with: @@ -191,3 +191,4 @@ jobs: command: pages publish --project-name=wildebeest-${{ env.OWNER_LOWER }} . env: CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} + COMMIT_HASH: ${{ github.sha }} diff --git a/frontend/src/routes/(frontend)/layout.tsx b/frontend/src/routes/(frontend)/layout.tsx index 46be532..eb0b76d 100644 --- a/frontend/src/routes/(frontend)/layout.tsx +++ b/frontend/src/routes/(frontend)/layout.tsx @@ -26,6 +26,7 @@ export const instanceLoader = loader$< export default component$(() => { useContextProvider(InstanceConfigContext, instanceLoader.use().value) + const commitHash = getCommitHash() return ( <> @@ -52,7 +53,7 @@ export default component$(() => { ) diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 590ea90..8dfe854 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -2,9 +2,8 @@ import { defineConfig } from 'vite' import { qwikVite } from '@builder.io/qwik/optimizer' import { qwikCity } from '@builder.io/qwik-city/vite' import tsconfigPaths from 'vite-tsconfig-paths' -import { execSync } from 'child_process' -const commitHash = execSync('git rev-parse --short HEAD').toString().replace(/\n/g, '') +const commitHash = process.env['COMMIT_HASH']?.slice(0, 7) export default defineConfig(() => { return { diff --git a/package.json b/package.json index f0b449a..43abeff 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "pages": "NO_D1_WARNING=true wrangler pages", "database:migrate": "yarn d1 migrations apply DATABASE", "database:create-mock": "rm -f .wrangler/state/d1/DATABASE.sqlite3 && yarn database:migrate --local && node ./frontend/mock-db/run.mjs", - "dev": "yarn build && yarn database:migrate --local && yarn pages dev frontend/dist --d1 DATABASE --persist --compatibility-date=2022-12-20", + "dev": "export COMMIT_HASH=$(git rev-parse HEAD) && yarn build && yarn database:migrate --local && yarn pages dev frontend/dist --d1 DATABASE --persist --compatibility-date=2022-12-20", "test:ui": "yarn build && yarn database:create-mock && concurrently --success command-1 --kill-others \"yarn pages dev frontend/dist --d1 DATABASE --persist --port 6868 --compatibility-date=2022-12-20 || true\" \"yarn --cwd frontend jest --verbose\"", "deploy:init": "yarn pages project create wildebeest && yarn d1 create wildebeest", "deploy": "yarn build && yarn database:migrate && yarn pages publish frontend/dist --project-name=wildebeest"