-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (110 loc) · 4.3 KB
/
Copy pathdeploy.yml
File metadata and controls
123 lines (110 loc) · 4.3 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
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
name: Deploy to GitHub Pages
on:
push:
branches:
- release
- development
- testing
permissions:
contents: write
concurrency:
group: deploy-gh-pages
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Set environment variables
id: set-env
run: |
if [ '${{ github.ref }}' = 'refs/heads/release' ]; then
echo "build_env=production" >> $GITHUB_OUTPUT
echo "path=app" >> $GITHUB_OUTPUT
echo "page_root=/CheemsBonkGame/app/" >> $GITHUB_OUTPUT
echo "build_prefix=prod" >> $GITHUB_OUTPUT
elif [ '${{ github.ref }}' = 'refs/heads/testing' ]; then
echo "build_env=development" >> $GITHUB_OUTPUT
echo "path=test" >> $GITHUB_OUTPUT
echo "page_root=/CheemsBonkGame/test/" >> $GITHUB_OUTPUT
echo "build_prefix=test" >> $GITHUB_OUTPUT
else
echo "build_env=development" >> $GITHUB_OUTPUT
echo "path=dev" >> $GITHUB_OUTPUT
echo "page_root=/CheemsBonkGame/dev/" >> $GITHUB_OUTPUT
echo "build_prefix=dev" >> $GITHUB_OUTPUT
fi
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Angular CLI
run: npm install -g @angular/cli
- name: Install dependencies
run: npm install
- name: Setup PWA
env:
build_prefix: ${{ steps.set-env.outputs.build_prefix }}
run: |
rm -rf public/img/icons/pwa
mkdir -p public/img/icons/pwa
cp .pwa/icons-$build_prefix/pwa/* public/img/icons/pwa
rm -f public/img/favicon.ico
cp .pwa/favicon-$build_prefix.ico public/img/favicon.ico
rm -f public/manifest.webmanifest
cp .pwa/manifest-$build_prefix.webmanifest public/manifest.webmanifest
- name: Build the application
env:
build_env: ${{ steps.set-env.outputs.build_env }}
page_root: ${{ steps.set-env.outputs.page_root }}
run: npm run build -- --configuration="$build_env" --base-href="$page_root"
- name: Clone gh-pages branch
env:
GH_PAT: ${{ secrets.GH_PAT }}
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
if [ -n "$GH_PAT" ]; then
REPO_URL="https://x-access-token:${GH_PAT}@github.com/${{ github.repository }}.git"
else
REPO_URL="https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
fi
if git clone --branch gh-pages --single-branch "$REPO_URL" deploy-folder 2>/dev/null; then
echo "Cloned existing gh-pages branch."
else
echo "gh-pages branch does not exist yet. Creating orphan branch."
mkdir deploy-folder
cd deploy-folder
git init
git remote add origin "$REPO_URL"
git checkout --orphan gh-pages
cd ..
fi
- name: Update Target Environment Directory
env:
path: ${{ steps.set-env.outputs.path }}
build_env: ${{ steps.set-env.outputs.build_env }}
run: |
target_dir="deploy-folder/$path"
echo "Removing and recreating target directory: $target_dir"
rm -rf "$target_dir"
mkdir -p "$target_dir"
cp -r dist/cheems-angular/browser/* "$target_dir/"
cp README.md .gitignore "$target_dir/" 2>/dev/null || true
if [ "$build_env" = "production" ]; then
cp .pwa/index.html "deploy-folder/" 2>/dev/null || true
cp README.md .gitignore "deploy-folder/" 2>/dev/null || true
fi
- name: Commit and Push to gh-pages
working-directory: deploy-folder
env:
GH_PAT: ${{ secrets.GH_PAT }}
run: |
git add .
if git diff --cached --quiet; then
echo "No changes to commit. Skipping deployment."
else
git commit -m "Deploy #${{ github.run_number }} from ${{ github.ref }} branch - ${{ steps.set-env.outputs.build_env }}"
git push origin HEAD:gh-pages
fi