forked from sugarlabs/musicblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (49 loc) · 1.76 KB
/
deployment.yml
File metadata and controls
59 lines (49 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: Deploy to GitHub Pages
on:
# Trigger only on push to master branch
push:
branches:
- master
# Allow manual trigger if needed
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
# Run only when the repository is the main repository
if: ${{ github.repository == 'sugarlabs/musicblocks'}}
steps:
# 1. Checkout the repository
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
# 2. Configure Git for GitHub Actions
- name: Configure Git
run: |
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
git config --global user.name "GitHub Actions"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# 3. Prepare the deployment directory
- name: Prepare deployment directory
run: |
mkdir -p ../deploy
cp -r * ../deploy/
# 4. Switch to the 'gh-pages' branch and pull latest changes
- name: Switch to gh-pages and pull latest changes
run: |
git checkout gh-pages || git checkout --orphan gh-pages
git pull origin gh-pages || true
git rm -rf . || true
git clean -fxd
# 5. Copy deployment files to the 'gh-pages' branch
- name: Copy files to gh-pages
run: |
cp -r ../deploy/* .
rm -rf ../deploy
# 6. Commit and push changes to GitHub Pages
- name: Commit and push changes
run: |
git add .
git commit -m "Deploy updates from $(date)" || echo "No changes to commit"
git pull origin gh-pages || true
git push origin gh-pages || true