Skip to content

Commit 5c3d159

Browse files
committed
Merge branch 'deployment-pipeline-added' of https://github.com/justin212407/musicblocks into deployment-pipeline-added
2 parents 2407c26 + 2a2e8a5 commit 5c3d159

File tree

1 file changed

+75
-12
lines changed

1 file changed

+75
-12
lines changed

.github/workflows/deploy.yml

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,103 @@
1-
name: Deploy
1+
name: Deploy to GitHub Pages with Tests
22

33
on:
44
push:
55
branches:
6-
- master
6+
- main
77
pull_request:
88
branches:
9-
- master
9+
- main
1010
workflow_dispatch:
1111

1212
jobs:
13+
test:
14+
name: Run Jest Tests
15+
runs-on: ubuntu-latest
16+
permissions:
17+
pull-requests: write
18+
contents: read
19+
issues: write
20+
21+
steps:
22+
- name: Checkout Repository
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: '20'
29+
30+
- name: Install Dependencies
31+
run: npm install
32+
33+
- name: Run Jest Tests
34+
id: jest
35+
run: |
36+
npm test -- --json --outputFile=jest-results.json || echo "TESTS_FAILED=true" >> $GITHUB_ENV
37+
38+
- name: Read Jest Results
39+
id: results
40+
run: |
41+
if [ -z "$TESTS_FAILED" ]; then
42+
TESTS_FAILED=false
43+
fi
44+
if [ ! -f jest-results.json ]; then
45+
echo "TESTS_FAILED=true" >> $GITHUB_ENV
46+
fi
47+
if [ "$TESTS_FAILED" = "true" ]; then
48+
echo "TESTS_PASSED=false" >> $GITHUB_ENV
49+
else
50+
echo "TESTS_PASSED=true" >> $GITHUB_ENV
51+
fi
52+
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH" 2>/dev/null || echo "0")
53+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_OUTPUT
54+
55+
- name: Comment on PR
56+
if: ${{ github.event_name == 'pull_request' }}
57+
uses: thollander/actions-comment-pull-request@v3
58+
with:
59+
pr-number: ${{ steps.results.outputs.PR_NUMBER }}
60+
github-token: ${{ secrets.GITHUB_TOKEN }}
61+
message: |
62+
${{ steps.results.outputs.PR_NUMBER }}
63+
${{ env.TESTS_FAILED == 'true' && '❌ Some Jest tests failed.' || '✅ All Jest tests passed!'}}
64+
1365
deploy:
66+
name: Deploy to GitHub Pages
1467
runs-on: ubuntu-latest
68+
needs: test
69+
if: github.repository == 'sugarlabs/musicblocks' && needs.test.outputs.TESTS_PASSED == 'true'
1570

1671
steps:
1772
- name: Checkout repository
1873
uses: actions/checkout@v3
19-
with:
20-
token: ${{ secrets.GITHUB_TOKEN }}
21-
22-
- name: Set up Git
74+
75+
- name: Configure Git
2376
run: |
2477
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
2578
git config --global user.name "GitHub Actions"
2679
git config --global user.email "github-actions[bot]@users.noreply.github.com"
27-
28-
- name: Deploy to GitHub Pages
80+
81+
- name: Prepare deployment directory
2982
run: |
3083
mkdir -p ../deploy
3184
cp -r * ../deploy/
85+
86+
- name: Switch to gh-pages and pull latest changes
87+
run: |
3288
git checkout gh-pages || git checkout --orphan gh-pages
33-
git rm -rf . > /dev/null 2>&1 || true
89+
git pull origin gh-pages || true
90+
git rm -rf . || true
3491
git clean -fxd
92+
93+
- name: Copy files to gh-pages
94+
run: |
3595
cp -r ../deploy/* .
3696
rm -rf ../deploy
97+
98+
- name: Commit and push changes
99+
run: |
37100
git add .
38101
git commit -m "Deploy updates from $(date)" || echo "No changes to commit"
39-
git push origin gh-pages
40-
102+
git pull origin gh-pages || true
103+
git push origin gh-pages || true

0 commit comments

Comments
 (0)