forked from wet-boew/GCWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (107 loc) · 4.61 KB
/
demo-deploy.yml
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: Demo Deployment
on:
push:
branches:
- main
- 'gcweb-pr*'
- demo-deploy
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository and initialize submodules
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive # This initializes and updates submodules automatically
# Step 2: Set up Node.js and Bower
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Bower
run: npm install -g bower
# Step 3: Install dependencies and build demo files
- name: Install dependencies
run: npm install --legacy-peer-deps
- name: Build Demo Files (GCWeb)
run: |
grunt demo --branch=${{ github.ref_name }}
docker compose up -d
- name: Build Demo Files (WET-BOEW)
run: grunt dist
# Step 4: Copy built files to the gh-pages directory
- name: Copy Built Files to gh-pages
run: |
# Ensure the gh-pages directory exists
mkdir -p ${{ github.workspace }}/gh-pages
# Copy the built files to gh-pages
if [ -d "./~sites" ]; then rsync -av ./~sites/ ${{ github.workspace }}/gh-pages/; fi
if [ -d "./dist" ]; then rsync -av ./dist/* ${{ github.workspace }}/gh-pages/; fi
# Step 4.5: Verify gh-pages Directory Contents
- name: Verify gh-pages Directory Contents
run: ls -R ${{ github.workspace }}/gh-pages
# Step 5: Clone or Ensure gh-pages Branch Exists and Update Submodule
- name: Dist - Update Submodule
run: |
# Define the gh-pages path
GHPAGES_PATH="${{ github.workspace }}/gh-pages"
# Check if gh-pages directory exists
if [ ! -d "$GHPAGES_PATH/.git" ]; then
# Clone or initialize the gh-pages branch if not already present
if git ls-remote --exit-code --heads https://github.com/${{ github.repository_owner }}/GCWeb.git gh-pages; then
git clone --depth 1 https://github.com/${{ github.repository_owner }}/GCWeb.git --branch gh-pages "$GHPAGES_PATH"
else
# Create an empty gh-pages branch if it doesn't exist
git clone --depth 1 https://github.com/${{ github.repository_owner }}/GCWeb.git "$GHPAGES_PATH"
cd "$GHPAGES_PATH"
git checkout --orphan gh-pages
git rm -rf .
touch .nojekyll # To prevent GitHub Pages from trying to process files as Jekyll
git commit --allow-empty -m "Initialize gh-pages branch"
git push origin gh-pages
cd ..
fi
else
echo "gh-pages directory already exists; skipping clone."
fi
# Move into the gh-pages directory and update the submodule
cd "$GHPAGES_PATH"
git submodule update --init --recursive
# Set Git user identity for commits in this environment
git config user.name "GitHub Actions"
git config user.email "[email protected]"
# If the submodule doesn't exist, add it
if [ ! -d "GCWeb" ]; then
git submodule add -b master https://github.com/ServiceCanada/wet-boew-demos.git GCWeb
fi
# Ensure we have the latest refs for the submodule's repository
cd GCWeb
git remote set-url origin https://github.com/ServiceCanada/wet-boew-demos.git
git fetch --depth 1 origin
# Try to reset to 'master'; if it doesn't exist, use 'gh-pages'
if git rev-parse --verify origin/master > /dev/null 2>&1; then
git reset --hard origin/master
elif git rev-parse --verify origin/gh-pages > /dev/null 2>&1; then
git reset --hard origin/gh-pages
else
echo "Neither 'master' nor 'gh-pages' branches found in the submodule repository."
exit 1
fi
cd ..
# Commit any changes and pull the latest gh-pages changes to avoid conflicts
git add .gitmodules GCWeb
git commit -m "Update submodule GCWeb" --allow-empty
git pull --rebase origin gh-pages || true # Ignore error if pull fails
# Step 6: Force Push to gh-pages Branch with Authentication
- name: Configure Remote with GitHub Token
run: |
cd ${{ github.workspace }}/gh-pages
# Set the remote URL to use the GitHub token for authentication
git remote set-url origin https://${{ secrets.GH_PAT }}@github.com/${{ github.repository_owner }}/GCWeb.git
# Step 7: Force Push to gh-pages
- name: Force Push to gh-pages
run: |
cd ${{ github.workspace }}/gh-pages
# Force push changes to gh-pages
git push origin gh-pages --force