-
Notifications
You must be signed in to change notification settings - Fork 54
96 lines (77 loc) · 3.13 KB
/
deploy_web.yml
File metadata and controls
96 lines (77 loc) · 3.13 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
name: Deploy Flutter web
on:
push:
branches:
- main
paths:
- ".github/workflows/deploy_web.yml"
- "open_wearable/**"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: app-web-deployment
cancel-in-progress: true
env:
FLUTTER_PROJECT: open_wearable
DEPLOY_REPOSITORY: OpenEarable/app-web-deployment
DEPLOY_BRANCH: gh-pages
BASE_HREF: /
CUSTOM_DOMAIN: app.openwearables.com
jobs:
build-and-deploy:
name: Build and publish static web app
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v6
- name: Install Flutter
run: |
git clone https://github.com/flutter/flutter.git --depth 1 -b stable "$RUNNER_TEMP/flutter"
echo "$RUNNER_TEMP/flutter/bin" >> "$GITHUB_PATH"
- name: Show Flutter version
run: flutter --version
- name: Install dependencies
working-directory: ${{ env.FLUTTER_PROJECT }}
run: flutter pub get
- name: Build web bundle
working-directory: ${{ env.FLUTTER_PROJECT }}
run: flutter build web --release --base-href "${BASE_HREF}" --pwa-strategy=none
- name: Prepare GitHub Pages files
working-directory: ${{ env.FLUTTER_PROJECT }}
run: |
printf '%s\n' "${CUSTOM_DOMAIN}" > build/web/CNAME
cp build/web/index.html build/web/404.html
touch build/web/.nojekyll
- name: Publish to deployment repository
env:
DEPLOY_TOKEN: ${{ secrets.APP_WEB_DEPLOYMENT_TOKEN }}
run: |
if [ -z "${DEPLOY_TOKEN}" ]; then
echo "::error::Missing APP_WEB_DEPLOYMENT_TOKEN secret."
echo "Create a fine-grained PAT with Contents: Read and write for ${DEPLOY_REPOSITORY} and save it as APP_WEB_DEPLOYMENT_TOKEN in this repository."
exit 1
fi
git config --global url."https://x-access-token:${DEPLOY_TOKEN}@github.com/".insteadOf "https://github.com/"
deploy_dir="$RUNNER_TEMP/app-web-deployment"
rm -rf "$deploy_dir"
if git ls-remote --exit-code --heads "https://github.com/${DEPLOY_REPOSITORY}.git" "${DEPLOY_BRANCH}" >/dev/null 2>&1; then
git clone --depth 1 --branch "${DEPLOY_BRANCH}" "https://github.com/${DEPLOY_REPOSITORY}.git" "$deploy_dir"
else
git clone --depth 1 "https://github.com/${DEPLOY_REPOSITORY}.git" "$deploy_dir"
cd "$deploy_dir"
git checkout --orphan "${DEPLOY_BRANCH}"
find . -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
fi
cd "$deploy_dir"
find . -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
cp -R "$GITHUB_WORKSPACE/${FLUTTER_PROJECT}/build/web/." .
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add --all
if git diff --cached --quiet; then
echo "No deployment changes to publish."
exit 0
fi
git commit -m "Deploy OpenEarable web app from ${GITHUB_SHA}"
git push origin "${DEPLOY_BRANCH}"