test deployment #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 a temporary directory for deployment | |
- name: Copy Built Files | |
run: | | |
mkdir -p demo_files | |
if [ -d "./~sites" ]; then rsync -av ./~sites/ demo_files/; fi | |
if [ -d "./dist" ]; then rsync -av ./dist/* demo_files/; fi | |
# Step 5: Clone or Create the gh-pages Branch and Update Submodule | |
- name: Dist - Update Submodule | |
run: | | |
# Check if the gh-pages branch exists and clone it, or create it if not | |
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 ~/gh-pages | |
else | |
# Create an empty gh-pages branch if it doesn't exist | |
git clone --depth 1 https://github.com/${{ github.repository_owner }}/GCWeb.git ~/gh-pages | |
cd ~/gh-pages | |
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 | |
# Move into the gh-pages directory and update the submodule | |
cd ~/gh-pages | |
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 and push the submodule update | |
git add .gitmodules GCWeb | |
git commit -m "Update submodule GCWeb" --allow-empty | |
# Step 6: Deploy updated submodule to gh-pages | |
- name: Dist - Deploy Submodule Updated | |
uses: ad-m/github-push-action@master | |
with: | |
repository: ${{ github.repository_owner }}/GCWeb | |
directory: ~/gh-pages | |
branch: gh-pages | |
github_token: ${{ secrets.GH_PAT }} |