Skip to content

Commit 707a764

Browse files
authored
Update node.js.yml
1 parent a7a6cc7 commit 707a764

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

.github/workflows/node.js.yml

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,50 @@ concurrency:
2020
cancel-in-progress: true
2121

2222
jobs:
23+
get-branches:
24+
runs-on: ubuntu-latest
25+
outputs:
26+
branches: ${{ steps.get-branches.outputs.branches }}
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- name: Get list of remote branches and their hashes
31+
id: get-branches
32+
run: |
33+
git fetch --all
34+
branches="$(git for-each-ref --format='{"name":"%(refname:short)","hash":"%(objectname)"}' refs/remotes/origin/ | sed 's|origin/||' | jq -sc .)"
35+
echo "branches=$branches" >> $GITHUB_OUTPUT
36+
2337
build:
2438
runs-on: ubuntu-latest
39+
needs: get-branches
40+
continue-on-error: true
41+
outputs:
42+
branches: ${{ needs.get-branches.outputs.branches }}
43+
44+
strategy:
45+
matrix:
46+
branches: ${{fromJson(needs.get-branches.outputs.branches)}}
2547

2648
steps:
2749
- uses: actions/checkout@v4
50+
with:
51+
ref: ${{ matrix.branches.name }}
2852

2953
- name: Use Node.js
3054
uses: actions/setup-node@v4
3155

3256
- name: Build web app
3357
run: |
58+
[ -d "puck-ntag215-manager" ]
3459
cd puck-ntag215-manager
3560
npm install --no-optional
3661
npm run build
37-
62+
3863
- name: Upload artifact
39-
uses: actions/upload-pages-artifact@v3
64+
uses: actions/upload-artifact@v4
4065
with:
66+
name: ${{ matrix.branches.hash }}
4167
path: ./puck-ntag215-manager/dist/
4268

4369
# Deployment job
@@ -48,7 +74,36 @@ jobs:
4874

4975
runs-on: ubuntu-latest
5076
needs: build
77+
5178
steps:
79+
- name: Download all artifacts
80+
uses: actions/download-artifact@v4
81+
with:
82+
path: "artifacts"
83+
84+
- name: Prepare artifacts
85+
env:
86+
branches: ${{ needs.build.outputs.branches }}
87+
88+
run: |
89+
mkdir -p "dist/"
90+
echo "$branches" | jq -c '.[]' | while read -r branch; do
91+
name="$(echo "$branch" | jq -r '.name')"
92+
hash="$(echo "$branch" | jq -r '.hash')"
93+
94+
if [ "$name" == "master" ]; then
95+
mv "artifacts/$hash"/* "dist/"
96+
else
97+
mkdir -p "dist/$name"
98+
mv "artifacts/$hash"/* "dist/$name/"
99+
fi
100+
done
101+
102+
- name: Upload artifact
103+
uses: actions/upload-pages-artifact@v3
104+
with:
105+
path: dist/
106+
52107
- name: Deploy to GitHub Pages
53108
id: deployment
54109
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)