Skip to content

Commit 6ab7065

Browse files
authored
Merge pull request #27 from rtau/alpha-data
Allow publish of draft quality data on `/alpha/` path for testing
2 parents 6bbaee7 + 908319c commit 6ab7065

1 file changed

Lines changed: 68 additions & 1 deletion

File tree

.github/workflows/fetch-data.yml

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,50 @@
11
name: Data Fetching
22
on:
33
push:
4+
# branches-ignore:
5+
# - alpha
46
schedule:
57
- cron: "10 21 * * *" # 05:10 (HKT) daily
68
workflow_dispatch:
79

810
jobs:
911
Fetch-Route-Data:
1012
runs-on: ubuntu-latest
13+
permissions:
14+
actions: write
15+
contents: write
1116

17+
env:
18+
ALPHA_BRANCH_NAME: alpha
1219
steps:
1320
- name: Check out repository code
1421
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Check if alpha branch status
26+
id: alpha-check
27+
shell: bash
28+
run: |
29+
set -o xtrace
30+
if git rev-parse --verify --no-revs "origin/${ALPHA_BRANCH_NAME}" && ! git diff --exit-code --merge-base origin/master "origin/${ALPHA_BRANCH_NAME}" --
31+
then
32+
echo "alpha_newer=yes" >> "$GITHUB_OUTPUT"
33+
fi
34+
35+
- name: Set github page upload path by alpha branch status
36+
id: target-path
37+
shell: bash
38+
run: |
39+
set -o xtrace
40+
should_deploy_to_alpha=${{ steps.alpha-check.outputs.alpha_newer == 'yes' && github.ref_name == env.ALPHA_BRANCH_NAME }}
41+
if [ "${should_deploy_to_alpha}" == "true" ]
42+
then
43+
echo "target-path=alpha/" >> "$GITHUB_OUTPUT"
44+
else
45+
echo "target-path=/" >> "$GITHUB_OUTPUT"
46+
fi
47+
1548
- name: Setup Python environment
1649
uses: actions/setup-python@v5
1750
with:
@@ -20,10 +53,12 @@ jobs:
2053
cache: 'pip'
2154
cache-dependency-path: crawling/requirements.txt
2255
- name: Install dependencies
56+
shell: bash
2357
run: |
2458
python -m pip install --upgrade pip
2559
pip install -r ./crawling/requirements.txt
2660
- name: Crawling resources
61+
shell: bash
2762
env:
2863
REQUEST_LIMIT: "6"
2964
run: |
@@ -49,6 +84,12 @@ jobs:
4984
python ./crawling/routeCompare.py
5085
python ./crawling/mtrExits.py
5186
87+
- name: Update MD5
88+
shell: bash
89+
run: |
90+
md5sum routeFareList.min.json | cut -f1 -d ' ' | tr -d $'\n' > routeFareList.md5
91+
md5sum routeFareList.alpha.min.json | cut -f1 -d ' ' | tr -d $'\n' > routeFareList.alpha.md5
92+
5293
- name: Archive crawling outputs
5394
uses: actions/upload-artifact@v4
5495
if: always()
@@ -76,8 +117,10 @@ jobs:
76117
md5sum routeFareList.min.json | cut -f1 -d ' ' | tr -d $'\n' > routeFareList.md5
77118
md5sum routeFareList.alpha.min.json | cut -f1 -d ' ' | tr -d $'\n' > routeFareList.alpha.md5
78119
- name: create deployment folder
120+
shell: bash
79121
run: mkdir -p build
80122
- name: cp files into deployment folder
123+
shell: bash
81124
run: |
82125
cp \
83126
routeFareList.json \
@@ -91,11 +134,35 @@ jobs:
91134
0versions.json \
92135
build/
93136
- name: cp route-ts into deployment folder
137+
shell: bash
94138
run: cp -r route-ts build
139+
140+
- name: Copy master build to alpha when no update or not exist
141+
if: github.ref_name == 'master' && steps.alpha-check.outputs.alpha_newer != 'yes'
142+
uses: JamesIves/github-pages-deploy-action@v4
143+
with:
144+
target-folder: alpha/
145+
folder: build
146+
commit-message: "Update resources from ${{ github.run_number }}:${{ github.run_attempt }}"
147+
branch: gh-pages
148+
clean: false
149+
clean-exclude: |
150+
alpha/*
151+
95152
- name: Update resources
96153
uses: JamesIves/github-pages-deploy-action@v4
97154
with:
155+
target-folder: ${{ steps.target-path.outputs.target-path }}
98156
folder: build
99-
commit-message: Update resources
157+
commit-message: "Update resources from ${{ github.run_number }}:${{ github.run_attempt }}"
100158
branch: gh-pages
101159
clean: false
160+
clean-exclude: |
161+
alpha/*
162+
163+
- name: Trigger alpha build on schedule
164+
if: ( github.event_name == 'schedule' || github.event_name=='workflow_dispatch') && steps.alpha-check.outputs.alpha_newer == 'yes'
165+
uses: benc-uk/workflow-dispatch@v1
166+
with:
167+
workflow: ${{ github.workflow }}
168+
ref: ${{ env.ALPHA_BRANCH_NAME }}

0 commit comments

Comments
 (0)