diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 2a1657979..b0fd68b1e 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -11,6 +11,7 @@ jobs: env: PREVIEW_HOSTNAME: ep-preview.click GITHUB_BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + GITHUB_COMMIT_HASH: ${{ github.event.pull_request.head.sha }} steps: - name: Checkout @@ -33,15 +34,12 @@ jobs: - name: Install dependencies run: make install - - name: Get current branch name - run: | - BRANCH_NAME=$(make safe_branch BRANCH=$GITHUB_BRANCH_NAME) - echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV - - name: Build the website - run: - make build MODE=preview - SITE_URL="https://${BRANCH_NAME}.ep-preview.click" + env: + BRANCH: "${{ env.GITHUB_BRANCH_NAME }}" + GIT_VERSION: "${{ env.GITHUB_COMMIT_HASH }}" + MODE: "preview" + run: make build - name: Set up SSH key uses: webfactory/ssh-agent@v0.9.1 @@ -52,7 +50,9 @@ jobs: run: ssh-keyscan "static.europython.eu" > ~/.ssh/known_hosts - name: Upload preview - run: make preview BRANCH=$GITHUB_BRANCH_NAME + env: + BRANCH: "${{ env.GITHUB_BRANCH_NAME }}" + run: make preview - name: Update PR Comment uses: actions/github-script@v7 @@ -80,7 +80,7 @@ jobs: } }); - const branch_name = process.env.BRANCH_NAME; + const branch_name = process.env.GITHUB_BRANCH_NAME; const url = "https://" + branch_name + "." + process.env.PREVIEW_HOSTNAME; const timestamp = new Date().toISOString(); const header = "\n|Key|Value|\n|---|---|\n" diff --git a/astro.config.mjs b/astro.config.mjs index 81f39e18b..a443f3246 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -13,20 +13,31 @@ import deleteUnusedImages from "astro-delete-unused-images"; import preload from "astro-preload"; import { execSync } from "node:child_process"; -let gitVersion = ""; -try { - gitVersion = execSync("git rev-parse --short HEAD 2>&1 > /dev/null"); -} catch (e) {} +let gitVersion = String(process.env.GIT_VERSION ?? "").slice(0, 7); + +if (!gitVersion) { + try { + gitVersion = execSync("git rev-parse --short HEAD", { + stdio: ["ignore", "pipe", "ignore"], + }) + .toString() + .trim(); + } catch { + gitVersion = "unknown"; + } +} // https://astro.build/config export default defineConfig({ vite: { define: { - "import.meta.env.TIMESTAMP": new Date() - .toISOString() - .replace(/[-:T.Z]/g, "") - .slice(0, 14), - "import.meta.env.GIT_VERSION": new String(gitVersion), + __TIMESTAMP__: JSON.stringify( + new Date() + .toISOString() + .replace(/[-:T.Z]/g, "") + .slice(0, 14) + ), + __GIT_VERSION__: JSON.stringify(gitVersion), }, resolve: { alias: { diff --git a/src/components/BaseHead.astro b/src/components/BaseHead.astro index 697172ae5..0bca0f0b3 100644 --- a/src/components/BaseHead.astro +++ b/src/components/BaseHead.astro @@ -5,8 +5,8 @@ interface Props { image?: string; } -const buildTimestamp = import.meta.env.TIMESTAMP; -const gitVersion = import.meta.env.GIT_VERSION; +const buildTimestamp = __TIMESTAMP__; +const gitVersion = __GIT_VERSION__; const canonicalURL = new URL(Astro.url.pathname, Astro.site); const { title, description, image = "/social-card.png" } = Astro.props; diff --git a/src/components/Footer.astro b/src/components/Footer.astro index 594df4740..eb80550b6 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -4,8 +4,8 @@ import { Fullbleed } from "./layout/fullbleed"; import links from "../data/links.json"; import { EPSLogo } from "./logo/eps-logo"; -const buildTimestamp = import.meta.env.TIMESTAMP; -const gitVersion = import.meta.env.GIT_VERSION; +const buildTimestamp = __TIMESTAMP__; +const gitVersion = __GIT_VERSION__; ---
diff --git a/src/env.d.ts b/src/env.d.ts index 107ecdf18..db4bfb864 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -10,3 +10,6 @@ interface ImportMetaEnv { interface ImportMeta { readonly env: ImportMetaEnv; } + +declare const __GIT_VERSION__: string; +declare const __TIMESTAMP__: string;