-
Notifications
You must be signed in to change notification settings - Fork 3
103 lines (82 loc) · 3.33 KB
/
Copy pathdeploy_web.yml
File metadata and controls
103 lines (82 loc) · 3.33 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
name: Deploy Web
on:
workflow_dispatch:
jobs:
deploy:
name: Build & Deploy to Web Branch
runs-on: ubuntu-latest
permissions:
contents: write # needed to push the deploy branch
pull-requests: write # needed for gh pr create
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Create .env file
run: echo "MAPBOX_TOKEN=${{ secrets.MAPBOX_TOKEN }}" > .env
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: "3.44.0"
cache: true
- name: Get dependencies
run: flutter pub get
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Build Flutter web — try WASM first, fall back to standard JS
- name: Build web (with --wasm)
id: build_wasm
run: flutter build web --wasm
continue-on-error: true
- name: Build web (fallback without --wasm)
if: steps.build_wasm.outcome == 'failure'
run: flutter build web
# Copy build output somewhere safe before we switch branches
- name: Stash build output
run: cp -r build/web /tmp/flutter-web-build
# Blank .env so no secrets end up in the deployed branch
- name: Clear .env in build output
run: echo -n > /tmp/flutter-web-build/.env
# Create the deploy branch FROM web so it shares history,
# then replace its content with the fresh build output.
# This gives GitHub a proper base…head diff for the PR.
- name: Push build to staging branch
run: |
set -e
DEPLOY_BRANCH="web-deploy/${{ github.run_number }}"
if git ls-remote --exit-code --heads origin web; then
git fetch origin web --depth=1
git checkout -B "$DEPLOY_BRANCH" origin/web
else
echo "web branch does not exist yet — creating orphan"
git checkout --orphan "$DEPLOY_BRANCH"
fi
# Wipe tracked files so we start clean
git rm -rf . --quiet || true
# Copy new build output into the working tree
cp -r /tmp/flutter-web-build/. .
git add -A
git commit -m "chore: web build #${{ github.run_number }}"
git push origin "$DEPLOY_BRANCH" --force
- name: Open PR from staging branch to web
run: |
gh pr create \
--base web \
--head "web-deploy/${{ github.run_number }}" \
--title "chore: deploy web build #${{ github.run_number }}" \
--body "## 🚀 Web Deploy
Automated web build triggered by [@${{ github.actor }}](https://github.com/${{ github.actor }}) via the **Deploy Web** workflow.
| Detail | Value |
|--------|-------|
| Run | #${{ github.run_number }} |
| Triggered by | @${{ github.actor }} |
| Source branch | \`${{ github.ref_name }}\` |
| Build mode | WASM (with fallback to JS) |
> ⚠️ The \`.env\` file has been cleared in this build. Secrets are managed via GitHub Secrets." \
--label "web-deploy" \
--label "automated"