forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 1
123 lines (111 loc) 路 4.67 KB
/
railway-update.yml
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: Update Dockerfile for Railway.app
# The workflow was EOL before its birth.
# https://github.com/DIYgod/RSSHub/pull/9626
on:
schedule:
- cron: '0 12 * * *' # only valid if the workflow exists in the default branch
workflow_dispatch: ~
jobs:
check-env:
permissions:
contents: none
runs-on: ubuntu-latest
outputs:
check-downstream: ${{ steps.check-downstream.outputs.downstream }}
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: check-downstream
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
name: Check downstream
if: ${{ env.DOCKER_USERNAME != '' && env.DOCKER_USERNAME != 'diygod' }}
run: echo "::set-output name=downstream::true"
- id: set-matrix
name: Set matrix
run: |
U='[ { "type": "upstream", "ref": "railway", "fallback-ref": "railway-downstream" } ]'
D='[ { "type": "downstream", "ref": "railway-downstream", "fallback-ref": "railway" } ]'
if [ '${{ steps.check-downstream.outputs.downstream }}' == 'true' ]; then
echo ::set-output name=matrix::{\"include\":$(jq -c --argjson u "$U" --argjson d "$D" -n '$u+$d')}
else
echo ::set-output name=matrix::{\"include\":$(echo $U | jq -c)}
fi
upstream:
runs-on: ubuntu-latest
needs: check-env
strategy:
matrix: ${{ fromJson(needs.check-env.outputs.matrix) }}
name: Update Dockerfile (${{ matrix.type }})
permissions:
contents: write
steps:
- name: Checkout (master)
id: checkout-master
uses: actions/checkout@v3
continue-on-error: true # would fail if the repo is created by Railway.app
with:
ref: master
- name: Checkout (${{ matrix.ref }})
if: steps.checkout-master.outcome == 'failure'
id: checkout-self
uses: actions/checkout@v3
continue-on-error: true
with:
ref: ${{ matrix.ref }}
- name: Checkout (fallback)
if: steps.checkout-self.outcome == 'failure'
uses: actions/checkout@v3
with:
ref: ${{ matrix.ref-fallback }}
- name: Set up deploy folder
id: deploy-folder
run: |
set -ex
if [ $(git branch --show-current) == 'master' ]; then
mkdir -p railway/
cp --parents .github/workflows/railway-update.yml railway/
cp --parents -r scripts/railway/ railway/
mv railway/scripts/railway/README.md railway/README.md
ls -lah railway/
echo ::set-output name=path::railway
echo ::set-output name=dockerfile::railway/Dockerfile
else
echo ::set-output name=path::.
echo ::set-output name=dockerfile::Dockerfile
fi
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: '3.10'
# Why Python? Oh, do you really love introducing tons of third-party (recursive) dependencies from npm?
# Once deployed via the "Deploy on Railway" button, there's NO WAY to remotely upgrade the dependencies of this
# workflow for users. (refer to scripts/railway/README.md for more details)
# Indeed, there are some workarounds to write a JS without any third-party dependencies, but, wow, I mean, it is
# even uglier and more human-unfriendly than introducing a Python script.
- name: Update Dockerfile (upstream)
if: ${{ matrix.type == 'upstream' }}
run: python -u scripts/railway/update.py
env:
DOCKERFILE: ${{ steps.deploy-folder.outputs.dockerfile }}
# step output with secrets will be ignored, we have no choice but to use a separate step to read the secret
- name: Update Dockerfile (downstream)
if: ${{ matrix.type == 'downstream' }}
run: python -u scripts/railway/update.py
env:
USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKERFILE: ${{ steps.deploy-folder.outputs.dockerfile }}
- name: Get current date
id: date
run: echo "::set-output name=date::$(date -uIseconds)"
# FIXME: buggy, please replace the action with a .github-un-sanitized one
# https://github.com/JamesIves/github-pages-deploy-action/discussions/1075#discussion-4000071
- name: Push
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: ${{ matrix.ref }}
folder: ${{ steps.deploy-folder.outputs.path }}
clean: false
git-config-name: github-actions[bot]
git-config-email: 41898282+github-actions[bot]@users.noreply.github.com
commit-message: Updated ${{ steps.date.outputs.date }}
single-commit: true