From aaeea8d858e55e20dd9af8d4f23ca98300fdb299 Mon Sep 17 00:00:00 2001
From: Ege Akman
Date: Mon, 20 Jan 2025 11:34:59 -0500
Subject: [PATCH 1/5] Add deployment automation (#961)
---------
Co-authored-by: Cyril Bitterich
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Artur Czepiel
---
.github/workflows/build-deploy.yml | 46 +++++++++++++
.github/workflows/preview.yml | 102 +++++++++++++++++++++++++++++
Makefile | 70 ++++++++++++++++++++
src/components/footer.astro | 5 ++
4 files changed, 223 insertions(+)
create mode 100644 .github/workflows/build-deploy.yml
create mode 100644 .github/workflows/preview.yml
create mode 100644 Makefile
diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml
new file mode 100644
index 000000000..643969638
--- /dev/null
+++ b/.github/workflows/build-deploy.yml
@@ -0,0 +1,46 @@
+name: Deploy to Server
+
+on:
+ workflow_dispatch:
+ push:
+ branches:
+ - ep2025
+
+jobs:
+ deploy:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ - name: Set timestamp for build/deploy
+ run: echo "TIMESTAMP=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
+
+ - name: Set up pnpm
+ uses: pnpm/action-setup@v4
+ with:
+ run_install: false
+
+ - name: Set up Node.js
+ uses: actions/setup-node@v4
+ with:
+ node-version: 20
+ cache: "pnpm"
+
+ - name: Install dependencies
+ run: make install
+
+ - name: Build the website
+ run: make build
+
+ - name: Set up SSH key
+ uses: webfactory/ssh-agent@v0.9.0
+ with:
+ ssh-private-key: ${{ secrets.DEPLOY_SSH_KEY }}
+
+ - name: ssh keyscan
+ run: ssh-keyscan "static.europython.eu" > ~/.ssh/known_hosts
+
+ - name: Deploy to server
+ run: make deploy FORCE_DEPLOY=true
diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml
new file mode 100644
index 000000000..8998fa3b1
--- /dev/null
+++ b/.github/workflows/preview.yml
@@ -0,0 +1,102 @@
+name: Preview
+
+on:
+ pull_request:
+
+jobs:
+ preview:
+ name: Run preview
+ runs-on: ubuntu-latest
+ env:
+ PREVIEW_HOSTNAME: ep-preview.click
+ GITHUB_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Set timestamp for build/deploy
+ run: echo "TIMESTAMP=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
+
+ - name: Set up pnpm
+ uses: pnpm/action-setup@v4
+ with:
+ run_install: false
+
+ - name: Set up Node.js
+ uses: actions/setup-node@v4
+ with:
+ node-version: 20
+ cache: "pnpm"
+
+ - name: Install dependencies
+ run: make install
+
+ - name: Build the website
+ run: make build
+
+ - name: Set up SSH key
+ uses: webfactory/ssh-agent@v0.9.0
+ with:
+ ssh-private-key: ${{ secrets.DEPLOY_SSH_KEY }}
+
+ - name: Get current branch name
+ run: |
+ BRANCH_NAME=$(make safe_branch BRANCH=$GITHUB_BRANCH_NAME)
+ echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
+
+ - name: ssh keyscan
+ run: ssh-keyscan "static.europython.eu" > ~/.ssh/known_hosts
+
+ - name: Upload preview
+ run: make preview BRANCH=$GITHUB_BRANCH_NAME
+
+ - name: Update PR Comment
+ uses: actions/github-script@v6
+ if: github.event_name == 'pull_request'
+
+ with:
+ github-token: ${{ secrets.GITHUB_TOKEN }}
+ script: |
+ console.log("Hello world!");
+ const pr_id = ${{ github.event.number }};
+ console.log("PR Id %d", pr_id);
+
+ comments = await github.paginate(github.rest.issues.listComments, {
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: Number(pr_id)
+ })
+
+ const preview_identifier = "# Preview available"
+
+ let comment_id = null;
+ comments.forEach(comment => {
+ if(comment.body.indexOf(preview_identifier) >= 0) {
+ comment_id = comment.id;
+ }
+ });
+
+ const branch_name = process.env.BRANCH_NAME;
+ const url = "https://" + branch_name + "." + process.env.PREVIEW_HOSTNAME;
+ const timestamp = new Date().toISOString();
+ const header = "\n|Key|Value|\n|---|---|\n"
+ const body = preview_identifier + header + "|url|" + url + "|\n|last update|" + timestamp + "|";
+
+ if(comment_id > 0) {
+ await github.rest.issues.updateComment({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ comment_id: comment_id,
+ body: body
+ });
+
+ } else {
+
+ await github.rest.issues.createComment({
+ issue_number: Number(pr_id),
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ body: body
+ });
+ }
diff --git a/Makefile b/Makefile
new file mode 100644
index 000000000..612dfadee
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,70 @@
+#
+# Variables for remote host
+# =========================
+VPS_USER ?= static_content_user
+VPS_HOST ?= static.europython.eu
+VPS_PROD_PATH ?= /home/static_content_user/content/europython_websites/ep2025
+VPS_PREVIEW_PATH ?= /home/static_content_user/content/previews
+REMOTE_CMD=ssh $(VPS_USER)@$(VPS_HOST)
+
+# Variables for build/deploy
+# ==========================
+export TIMESTAMP ?= $(shell date +%Y%m%d%H%M%S)
+export GIT_VERSION ?= $(shell git rev-parse --short HEAD)
+
+# Variables for deploy
+# ====================
+# Auto-detect and sanitize current git branch
+BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
+# Replace "/" and other non-alphanumeric characters with "-"
+SAFE_BRANCH := $(shell echo "$(BRANCH)" | sed 's/[^A-Za-z0-9._-]/-/g')
+FORCE_DEPLOY ?= false
+
+.PHONY: build deploy dev clean install
+
+
+safe_branch:
+ @echo $(SAFE_BRANCH)
+
+pre:
+ npm install -g pnpm
+
+install:
+ pnpm install
+
+dev:
+ pnpm dev
+
+clean:
+ git clean -fdX
+
+check:
+ pnpm run astro check
+
+build:
+ # TODO: update this to just `pnpm build` after resolving the astro-check warnings
+ pnpm run astro build
+ # NOTE: also let's find a better way to do this :D
+ find ./dist/_astro/ -iname '*.jpg' -delete
+
+preview: RELEASES_DIR = $(VPS_PREVIEW_PATH)/$(SAFE_BRANCH)/releases
+preview: TARGET = $(RELEASES_DIR)/$(TIMESTAMP)
+preview:
+ echo $(TARGET)
+ @echo "\n\n**** Deploying preview of a branch '$(BRANCH)' (safe: $(SAFE_BRANCH)) to $(TARGET)...\n\n"
+ $(REMOTE_CMD) "mkdir -p $(TARGET)"
+ rsync -avz --delete ./dist/ $(VPS_USER)@$(VPS_HOST):$(TARGET)/
+ $(REMOTE_CMD) "cd $(RELEASES_DIR) && ln -snf $(TIMESTAMP) current"
+ @echo "\n\n**** Preview complete.\n\n"
+
+
+ifeq ($(FORCE_DEPLOY), true)
+deploy: RELEASES_DIR = $(VPS_PROD_PATH)/$(SAFE_BRANCH)/releases
+deploy: TARGET = $(RELEASES_DIR)/$(TIMESTAMP)
+deploy:
+ @echo "\n\n**** Deploying branch '$(BRANCH)' (safe: $(SAFE_BRANCH)) to $(TARGET)...\n\n"
+ $(REMOTE_CMD) "mkdir -p $(TARGET)"
+ rsync -avz --delete ./dist/ $(VPS_USER)@$(VPS_HOST):$(TARGET)/
+ $(REMOTE_CMD) "cd $(RELEASES_DIR) && ln -snf $(TIMESTAMP) current"
+ @echo "\n\n**** Deployment complete.\n\n"
+endif
diff --git a/src/components/footer.astro b/src/components/footer.astro
index 86b6806a8..d86068bb8 100644
--- a/src/components/footer.astro
+++ b/src/components/footer.astro
@@ -4,6 +4,9 @@ import { Fullbleed } from "./layout/fullbleed";
import { LogoExtended } from "./logo/logo-extended";
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;
---
@@ -84,7 +87,9 @@ import { EPSLogo } from "./logo/eps-logo";
github.com/europython ↗
+ version: {gitVersion} @ {buildTimestamp}
+
From c9ab0604c64f49a4d75c6547d8883ad17d6a6a19 Mon Sep 17 00:00:00 2001
From: Artur Czepiel
Date: Mon, 20 Jan 2025 17:23:06 +0100
Subject: [PATCH 2/5] test simpler deployment (#965)
PR opened for testing if this even works via GHA :)
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Cyril Bitterich
---
src/components/footer.astro | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/components/footer.astro b/src/components/footer.astro
index d86068bb8..e3c13e298 100644
--- a/src/components/footer.astro
+++ b/src/components/footer.astro
@@ -91,5 +91,6 @@ const gitVersion = import.meta.env.GIT_VERSION;
+ version: {gitVersion} @ {buildTimestamp}
From c1485e8e55d7a79c157fcbd0c48c05144859ad30 Mon Sep 17 00:00:00 2001
From: Artur Czepiel
Date: Mon, 20 Jan 2025 17:15:48 +0100
Subject: [PATCH 3/5] add previews (#966)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Cyril Bitterich
From 00c12af5cf7eb4c242135cb727c64e586ee9d470 Mon Sep 17 00:00:00 2001
From: egeakman
Date: Mon, 24 Feb 2025 12:14:36 -0500
Subject: [PATCH 4/5] Adapt 2024
---
.github/workflows/build-deploy.yml | 1 +
Makefile | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml
index 643969638..c730b00c9 100644
--- a/.github/workflows/build-deploy.yml
+++ b/.github/workflows/build-deploy.yml
@@ -4,6 +4,7 @@ on:
workflow_dispatch:
push:
branches:
+ - ep2024
- ep2025
jobs:
diff --git a/Makefile b/Makefile
index 612dfadee..700b4663f 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
# =========================
VPS_USER ?= static_content_user
VPS_HOST ?= static.europython.eu
-VPS_PROD_PATH ?= /home/static_content_user/content/europython_websites/ep2025
+VPS_PROD_PATH ?= /home/static_content_user/content/europython_websites/ep2024
VPS_PREVIEW_PATH ?= /home/static_content_user/content/previews
REMOTE_CMD=ssh $(VPS_USER)@$(VPS_HOST)
From 3dca4fb80e2b6609e7029d5ac98430161b711ac9 Mon Sep 17 00:00:00 2001
From: Ege Akman
Date: Mon, 24 Feb 2025 12:22:39 -0500
Subject: [PATCH 5/5] Update src/components/footer.astro
---
src/components/footer.astro | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/components/footer.astro b/src/components/footer.astro
index e3c13e298..94bb36426 100644
--- a/src/components/footer.astro
+++ b/src/components/footer.astro
@@ -90,7 +90,5 @@ const gitVersion = import.meta.env.GIT_VERSION;
version: {gitVersion} @ {buildTimestamp}
-
- version: {gitVersion} @ {buildTimestamp}