Skip to content

Commit aac9d2b

Browse files
egeakmannikoshell
andauthored
Fix branch name sanitation in preview (#1272)
Fixes #1273 --------- Co-authored-by: Niko <[email protected]>
1 parent 8cf2f8b commit aac9d2b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

.github/workflows/preview.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ jobs:
5454
BRANCH: "${{ env.GITHUB_BRANCH_NAME }}"
5555
run: make preview
5656

57+
- name: Get safe branch and export to env
58+
env:
59+
BRANCH: ${{ env.GITHUB_BRANCH_NAME }}
60+
run: |
61+
echo "SAFE_BRANCH=$(make safe_branch)" >> $GITHUB_ENV
62+
5763
- name: Update PR Comment
5864
uses: actions/github-script@v7
5965
if: github.event_name == 'pull_request'
@@ -80,8 +86,8 @@ jobs:
8086
}
8187
});
8288
83-
const branch_name = process.env.GITHUB_BRANCH_NAME;
84-
const url = "https://" + branch_name + "." + process.env.PREVIEW_HOSTNAME;
89+
const safe_branch = process.env.SAFE_BRANCH;
90+
const url = "https://" + safe_branch + "." + process.env.PREVIEW_HOSTNAME;
8591
const timestamp = new Date().toISOString();
8692
const header = "\n|Key|Value|\n|---|---|\n"
8793
const body = preview_identifier + header + "|url|" + url + "|\n|last update|" + timestamp + "|";

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export GIT_VERSION ?= $(shell git rev-parse --short HEAD)
1818
# Auto-detect and sanitize current git branch
1919
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
2020
# Replace "/" and other non-alphanumeric characters with "-"
21-
SAFE_BRANCH := $(shell echo "$(BRANCH)" | sed 's/[^A-Za-z0-9-]/-/g')
21+
SAFE_BRANCH := $(shell echo "$(BRANCH)" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]/-/g')
2222
FORCE_DEPLOY ?= false
2323
SITE_URL ?= "https://$(SAFE_BRANCH).ep-preview.click"
2424

0 commit comments

Comments
 (0)