Skip to content

Commit f9b92aa

Browse files
committed
Make deploy trigger only on new version
1 parent be43a67 commit f9b92aa

File tree

4 files changed

+51
-22
lines changed

4 files changed

+51
-22
lines changed

.github/workflows/build-website.yml

+25-21
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ name: Build website
55

66
on:
77
push:
8+
tags:
9+
- "v[0-9]+.[0-9]+.[0-9]+"
810
branches:
9-
- main
10-
- staging/**
11+
- "staging**"
1112
workflow_dispatch:
1213

1314
permissions:
@@ -19,6 +20,9 @@ concurrency:
1920

2021
jobs:
2122
build-website:
23+
# Note: `github.event.base_ref` is equal to `refs/heads/main` only when the workflow is triggered
24+
# by a lightweight tag (_not_ an annotated tag) placed on the last commit of the `main` branch
25+
if: github.event.base_ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/staging') || github.event_name == 'workflow_dispatch'
2226
runs-on: ubuntu-latest
2327
steps:
2428
- uses: actions/checkout@v4
@@ -36,7 +40,7 @@ jobs:
3640
- run: echo "APP_VERSION=$(jq -r '.version' package.json)" >> $GITHUB_ENV
3741
id: APP_VERSION
3842

39-
- run: echo "BRANCH=$([[ "$(git branch --show-current)" == "main" ]] && echo "dist" || echo "staging/dist")" >> $GITHUB_ENV
43+
- run: echo "BRANCH=$(${{ github.event.base_ref == 'refs/heads/main' || github.ref == 'refs/heads/main' }} && echo "dist" || echo "staging/dist")" >> $GITHUB_ENV
4044
id: BRANCH
4145

4246
- run: echo "SENTRY_ENVIRONMENT=$([[ "${{ env.BRANCH }}" == "dist" ]] && echo "production" || echo "staging")" >> $GITHUB_ENV
@@ -46,25 +50,25 @@ jobs:
4650
DOMAIN: "${{ secrets.DOMAIN }}"
4751
run: sed -i "s/\$DOMAIN/${{ env.DOMAIN }}/" index.html
4852

49-
- env:
50-
ENVIRONMENT: "${{ env.SENTRY_ENVIRONMENT }}"
51-
APP_VERSION: "${{ env.APP_VERSION }}"
52-
DOMAIN: "${{ secrets.DOMAIN }}"
53-
SENTRY_INGEST: "${{ secrets.SENTRY_INGEST }}"
54-
PLAUSIBLE_API_URL: "${{ secrets.PLAUSIBLE_API_URL }}"
55-
PB_INSTANCES: "${{ secrets.PB_INSTANCES }}"
56-
run: npm run build
53+
# - env:
54+
# ENVIRONMENT: "${{ env.SENTRY_ENVIRONMENT }}"
55+
# APP_VERSION: "${{ env.APP_VERSION }}"
56+
# DOMAIN: "${{ secrets.DOMAIN }}"
57+
# SENTRY_INGEST: "${{ secrets.SENTRY_INGEST }}"
58+
# PLAUSIBLE_API_URL: "${{ secrets.PLAUSIBLE_API_URL }}"
59+
# PB_INSTANCES: "${{ secrets.PB_INSTANCES }}"
60+
# run: npm run build
5761

58-
- run: |
59-
git checkout index.html
60-
[[ "${{ env.BRANCH }}" != "dist" ]] && git fetch && git branch main remotes/origin/main
61-
git switch --orphan ${{ env.BRANCH }}
62-
git checkout main netlify.toml
63-
git add docs
64-
git config user.name "Zwyx - GitHub Actions"
65-
git config user.email "[email protected]>"
66-
git commit -m "Build website"
67-
git push --set-upstream origin --force ${{ env.BRANCH }}
62+
# - run: |
63+
# git checkout index.html
64+
# [[ "${{ env.BRANCH }}" != "dist" ]] && git fetch && git branch main remotes/origin/main
65+
# git switch --orphan ${{ env.BRANCH }}
66+
# git checkout main netlify.toml
67+
# git add docs
68+
# git config user.name "Zwyx - GitHub Actions"
69+
# git config user.email "[email protected]>"
70+
# git commit -m "Build website"
71+
# git push --set-upstream origin --force ${{ env.BRANCH }}
6872
#
6973
# - name: Setup tmate session
7074
# if: ${{ always() }}

.vscode/settings.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@
2323
"AUTORERUN",
2424
"behavior",
2525
"CCPA",
26+
"dialog",
2627
"libraryofbabel",
2728
"lucide",
2829
"magick",
2930
"maskable",
3031
"mxschmitt",
32+
"nvmrc",
33+
"objectname",
34+
"objecttype",
3135
"onetime",
3236
"overscroll",
3337
"Popover",
3438
"Snelling",
35-
"usehooks"
39+
"usehooks",
40+
"Zwyx"
3641
]
3742
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"dev": "VITE_APP_VERSION=$(jq -r '.version' package.json) vite",
88
"build": "npm run lint && tsc && VITE_ENVIRONMENT=$ENVIRONMENT VITE_APP_VERSION=$APP_VERSION VITE_DOMAIN=$DOMAIN VITE_SENTRY_INGEST=$SENTRY_INGEST VITE_PLAUSIBLE_API_URL=$PLAUSIBLE_API_URL VITE_PB_INSTANCES=$PB_INSTANCES vite build",
99
"lint": "eslint --max-warnings=0 .",
10+
"postversion": "res/convert-annotated-tags-to-lightweight.sh",
1011
"preview": "vite preview",
1112
"eslint:print-active-rules": "eslint --print-config src/index.ts",
1213
"prettier": "prettier -w .",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo "Converting annotated tags to lightweight tags..."
6+
7+
git for-each-ref --format="%(objecttype) %(refname:short) %(*objectname)" "refs/tags/*" | while IFS= read -r line; do
8+
type=$(echo "$line" | cut -f 1 -d " ")
9+
tag=$(echo "$line" | cut -f 2 -d " ")
10+
hash=$(echo "$line" | cut -f 3 -d " ")
11+
12+
if [ "$type" = "tag" ]; then
13+
git tag -d "$tag"
14+
git tag "$tag" "$hash"
15+
fi
16+
done
17+
18+
echo "Tag conversion finished."
19+
echo

0 commit comments

Comments
 (0)