test deployment #34
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 # 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 5: Reinitialize gh-pages Branch Cleanly | |
- name: Reinitialize gh-pages Branch | |
run: | | |
GHPAGES_PATH="${{ github.workspace }}/gh-pages" | |
# Remove gh-pages directory if it exists | |
if [ -d "$GHPAGES_PATH" ]; then | |
rm -rf "$GHPAGES_PATH" | |
fi | |
# Reinitialize the gh-pages branch with a clean history | |
git clone https://github.com/${{ github.repository_owner }}/GCWeb.git "$GHPAGES_PATH" | |
cd "$GHPAGES_PATH" | |
git checkout --orphan gh-pages | |
git rm -rf . | |
touch .nojekyll | |
git add .nojekyll | |
# Set Git user identity for commits in this environment | |
git config user.name "GitHub Actions" | |
git config user.email "[email protected]" | |
# Commit and push to initialize the gh-pages branch | |
git commit -m "Reinitialize gh-pages branch" | |
git push --force origin gh-pages | |
# 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: Prepare for Force Push to gh-pages | |
run: | | |
cd ${{ github.workspace }}/gh-pages | |
# Repack the repository to avoid any potential issues with large or corrupt objects | |
git gc --prune=now | |
git repack -a -d --depth=250 --window=250 | |
# Retry force push changes to gh-pages | |
git push origin gh-pages --force |