Skip to content

Commit 2bd402d

Browse files
authored
fix: Update release.yml (#211)
Try the best parts of things that worked earlier. release.yml: Checks out the dist branch. Fetches the main branch. Overwrites the dist branch working tree with the files from main, except the dist directory. Builds the project (creating/updating the dist directory). Deploys to Firebase. Commits and force-pushes the dist directory to the dist branch.
1 parent e20d540 commit 2bd402d

File tree

1 file changed

+55
-45
lines changed

1 file changed

+55
-45
lines changed

.github/workflows/release.yml

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,59 +15,69 @@
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: Checkout code
32-
uses: actions/checkout@v3
33-
with:
34-
ref: dist
35-
token: ${{ secrets.GH_MERGE_TOKEN }}
36-
fetch-depth: 0
23+
release:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: write
27+
id-token: write # Needed for Firebase
28+
env:
29+
GOOGLE_MAPS_JS_SAMPLES_KEY: "${{ secrets.GOOGLE_MAPS_JS_SAMPLES_KEY }}"
30+
steps:
31+
- name: Checkout dist
32+
uses: actions/checkout@v3
33+
with:
34+
ref: dist # Checkout the *dist* branch initially.
35+
token: ${{ secrets.GH_MERGE_TOKEN }}
36+
fetch-depth: 0
3737

38-
- name: Set Git Identity
39-
run: |
40-
git config --global user.name 'googlemaps-bot'
41-
git config --global user.email '[email protected]'
38+
- name: Set Git Identity
39+
run: |
40+
git config --global user.name 'googlemaps-bot'
41+
git config --global user.email '[email protected]'
42+
43+
- name: Fetch main
44+
run: git fetch origin main:main
4245

43-
- uses: actions/cache@v3
44-
with:
45-
path: ~/.npm
46-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
47-
restore-keys: |
48-
${{ runner.os }}-node
46+
- name: Copy Files from Main (Except dist)
47+
run: |
48+
git checkout main -- .
49+
rm -rf dist
4950
50-
- uses: actions/setup-node@v3
51-
with:
52-
node-version: '22.x'
51+
- uses: actions/cache@v3
52+
with:
53+
path: ~/.npm
54+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
55+
restore-keys: |
56+
${{ runner.os }}-node
5357
54-
- run: npm i
55-
- run: npm run build-all
56-
57-
- uses: google-github-actions/auth@v1
58-
with:
59-
credentials_json: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_KEY }}
60-
61-
- name: Install Firebase CLI
62-
run: npm install -g firebase-tools
63-
64-
- name: Deploy to Firebase Hosting
65-
run: firebase deploy --only hosting
58+
- uses: actions/setup-node@v3
59+
with:
60+
node-version: '22.x'
6661

67-
- name: Force Checkout dist and Overwrite
68-
run: |
69-
git fetch origin main
70-
git checkout -B dist origin/main
71-
git add dist
62+
- run: npm i
63+
- run: npm run build-all
64+
65+
- uses: google-github-actions/auth@v1
66+
with:
67+
credentials_json: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_KEY }}
68+
69+
- name: Install Firebase CLI
70+
run: npm install -g firebase-tools
71+
72+
- name: Deploy to Firebase Hosting
73+
run: firebase deploy --only hosting
74+
75+
- name: Commit and Push Changes (to dist)
76+
run: |
77+
git add dist
78+
if git diff --staged --quiet; then
79+
echo "No changes to commit"
80+
else
7281
git commit -m "Update dist folder"
7382
git push --force origin dist
83+
fi

0 commit comments

Comments
 (0)