Skip to content
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
20 changes: 10 additions & 10 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/[email protected]
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down
29 changes: 20 additions & 9 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions src/components/BaseHead.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Footer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
---

<div class="mt-auto">
Expand Down
3 changes: 3 additions & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ interface ImportMetaEnv {
interface ImportMeta {
readonly env: ImportMetaEnv;
}

declare const __GIT_VERSION__: string;
declare const __TIMESTAMP__: string;