Skip to content

Commit 02f2123

Browse files
authored
fix: Simplify release workflow. (#170)
1 parent d0919d6 commit 02f2123

File tree

1 file changed

+47
-69
lines changed

1 file changed

+47
-69
lines changed

.github/workflows/release.yml

Lines changed: 47 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -15,85 +15,63 @@
1515
name: Release
1616

1717
on:
18-
push: # Trigger on pushes to main
18+
push:
1919
branches:
2020
- main
2121

2222
jobs:
23-
release:
24-
runs-on: ubuntu-latest
25-
permissions:
26-
contents: write
27-
id-token: write
28-
env:
29-
GOOGLE_MAPS_JS_SAMPLES_KEY: "${{ secrets.GOOGLE_MAPS_JS_SAMPLES_KEY }}"
30-
steps:
31-
- name: Clear GitHub Actions Cache (Force a Miss)
32-
uses: actions/cache@v3
33-
with:
34-
path: ~/.gitconfig
35-
key: gitconfig-${{ github.run_id }}
23+
release:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: write # Needed for pushing to dist
27+
id-token: write # Needed for Firebase deployment
28+
env:
29+
GOOGLE_MAPS_JS_SAMPLES_KEY: "${{ secrets.GOOGLE_MAPS_JS_SAMPLES_KEY }}"
30+
steps:
31+
- name: Checkout code (main branch)
32+
uses: actions/checkout@v3
33+
with:
34+
ref: main # Checkout *main*, not dist
35+
token: ${{ secrets.GH_MERGE_TOKEN }}
3636

37-
- name: Checkout code
38-
uses: actions/checkout@v3
39-
with:
40-
token: ${{ secrets.GITHUB_TOKEN }}
41-
42-
- name: Clear Git config cache
43-
run: |
44-
git config --global --unset-all user.name || true
45-
git config --global --unset-all user.email || true
37+
- name: Clear Git config cache (Global)
38+
run: |
39+
git config --global --unset-all user.name || true
40+
git config --global --unset-all user.email || true
4641
47-
- name: Set Git Identity
48-
run: |
49-
git config --global user.name 'googlemaps-bot'
50-
git config --global user.email '[email protected]'
42+
- name: Set Git Identity
43+
run: |
44+
git config --global user.name 'googlemaps-bot'
45+
git config --global user.email '[email protected]'
5146
52-
- uses: actions/cache@v3
53-
with:
54-
path: ~/.npm
55-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
56-
restore-keys: |
57-
${{ runner.os }}-node
58-
mode: 'max'
47+
- uses: actions/cache@v3
48+
with:
49+
path: ~/.npm
50+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
51+
restore-keys: |
52+
${{ runner.os }}-node
5953
60-
- uses: actions/setup-node@v3
61-
with:
62-
node-version: '22.x'
54+
- uses: actions/setup-node@v3
55+
with:
56+
node-version: '22.x'
6357

64-
- run: npm i
65-
- run: npm run build-all
58+
- run: npm i
59+
- run: npm run build-all
6660

67-
- uses: google-github-actions/auth@v1
68-
with:
69-
credentials_json: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_KEY }}
61+
- uses: google-github-actions/auth@v1
62+
with:
63+
credentials_json: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_KEY }}
7064

71-
- name: Install Firebase CLI
72-
run: npm install -g firebase-tools
65+
- name: Install Firebase CLI
66+
run: npm install -g firebase-tools
7367

74-
- name: Deploy to Firebase Hosting
75-
run: firebase deploy --only hosting
68+
- name: Deploy to Firebase Hosting
69+
run: firebase deploy --only hosting
7670

77-
- name: Check if the dist branch exists remotely
78-
run: |
79-
if git ls-remote --exit-code --heads origin dist; then
80-
# Delete the dist branch locally if it exists
81-
if git show-ref --verify --quiet refs/heads/dist; then
82-
git branch -D dist
83-
fi
84-
# Delete the dist branch remotely
85-
git push origin --delete dist
86-
fi
87-
88-
- name: Checkout and create dist branch from main
89-
run: git checkout -b dist main
90-
91-
- name: Add and commit changes to the dist folder
92-
run: |
93-
git add dist
94-
if [[ -n $(git status --porcelain) ]]; then
95-
git commit -m "Update dist folder"
96-
git push origin dist
97-
else
98-
echo "No changes to commit"
99-
fi
71+
- name: Force Checkout dist and Overwrite
72+
run: |
73+
git fetch origin main # Ensure we have the latest main
74+
git checkout -B dist origin/main # Force checkout of dist, overwriting with main
75+
git add dist
76+
git commit -m "Update dist folder [skip ci]"
77+
git push --force origin dist # Force push to dist

0 commit comments

Comments
 (0)