Skip to content

Commit 5c16178

Browse files
committed
Use GHA to build
1 parent c5aadbf commit 5c16178

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed

.github/workflows/ci.yml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-20.04
10+
steps:
11+
- name: Install dependencies
12+
run: |
13+
sudo apt update
14+
sudo apt install build-essential clang flex g++ gawk gcc-multilib gettext \
15+
git libncurses5-dev libssl-dev python3-distutils rsync unzip zlib1g-dev
16+
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
20+
- name: Hook the openwrt_core URL for opkg
21+
run: |
22+
TIME="$(curl "https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" | jq -r .created_at)"
23+
echo "ci-$(date -d "${TIME}" -u +'%Y%m%d-%H%M%S')-${GITHUB_SHA:0:8}" >version
24+
sed -i "s|%U/targets/%S/packages|https://hzyitc.github.io/openwrt-redmi-ax3000/${GITHUB_REF_NAME}/%R|" include/feeds.mk
25+
26+
- name: Update and install feeds
27+
run: |
28+
./scripts/feeds update -a
29+
./scripts/feeds install -a
30+
31+
- name: Configure
32+
run: |
33+
cat <<EOF | sed -E 's/^ //' >.config
34+
CONFIG_TARGET_ipq50xx=y
35+
CONFIG_TARGET_ipq50xx_arm=y
36+
CONFIG_TARGET_ipq50xx_arm_DEVICE_redmi_ax3000=y
37+
38+
CONFIG_ALL_NONSHARED=y
39+
CONFIG_REPRODUCIBLE_DEBUG_INFO=y
40+
41+
CONFIG_PACKAGE_luci=y
42+
EOF
43+
make defconfig
44+
45+
- name: Download
46+
run: |
47+
make -j16 download
48+
49+
- name: Build tools
50+
run: |
51+
make -j$(nproc) tools/install
52+
53+
- name: Build toolchain
54+
run: |
55+
make -j$(nproc) toolchain/install
56+
57+
- name: Build all
58+
run: |
59+
make -j$(nproc) IGNORE_ERRORS=1
60+
61+
- name: Upload bin to artifacts
62+
uses: actions/upload-artifact@v3
63+
with:
64+
name: bin-ipq50xx-arm
65+
path: bin/targets/ipq50xx/arm/*
66+
67+
- name: Upload dl to artifacts
68+
uses: actions/upload-artifact@v3
69+
with:
70+
name: dl
71+
path: dl/*
72+
73+
gh-pages:
74+
needs: [ build ]
75+
runs-on: ubuntu-20.04
76+
permissions:
77+
contents: write
78+
steps:
79+
- name: Checkout gh-pages
80+
uses: actions/checkout@v3
81+
with:
82+
path: 'gh-pages'
83+
ref: 'gh-pages'
84+
fetch-depth: 0
85+
86+
- name: Configure the git user
87+
run: |
88+
git config --global user.name 'github-actions[bot]'
89+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
90+
91+
- name: Drop old versions
92+
run: |
93+
cd gh-pages
94+
readarray -t old_version < <(git log --format='%h' -- "${GITHUB_REF_NAME}" | tail -n +10)
95+
GIT_SEQUENCE_EDITOR="sed -i '1 i break'" git rebase -i --root
96+
for commit in "${old_version[@]}"; do
97+
sed -i "/${commit}/d" .git/rebase-merge/git-rebase-todo
98+
done
99+
git rebase --continue
100+
101+
- name: Download bin from artifacts
102+
uses: actions/download-artifact@v3
103+
with:
104+
name: bin-ipq50xx-arm
105+
path: bin/
106+
107+
- name: Copy contents
108+
run: |
109+
version="$(cat "bin/version.buildinfo")"
110+
mkdir -p "gh-pages/${GITHUB_REF_NAME}/${version}/"
111+
cp -avr bin/packages/* "gh-pages/${GITHUB_REF_NAME}/${version}/"
112+
113+
- name: Commit
114+
run: |
115+
cd gh-pages
116+
git add .
117+
git commit -m "Add: ${GITHUB_REF_NAME}: $(cat ../bin/version.buildinfo)"
118+
119+
- name: Publish
120+
run: |
121+
cd gh-pages
122+
git push -f origin gh-pages
123+
124+
release:
125+
needs: [ build ]
126+
runs-on: ubuntu-20.04
127+
permissions:
128+
contents: write
129+
steps:
130+
- name: Checkout
131+
uses: actions/checkout@v3
132+
133+
- name: Download dl from artifacts
134+
uses: actions/download-artifact@v3
135+
with:
136+
name: dl
137+
path: dl/
138+
139+
- name: Download bin from artifacts
140+
uses: actions/download-artifact@v3
141+
with:
142+
name: bin-ipq50xx-arm
143+
path: bin/targets/ipq50xx/arm/
144+
145+
- name: Tar
146+
run: |
147+
tar cvf dl.tar -C dl/ .
148+
tar cvf bin-ipq50xx.tar -C bin/targets/ipq50xx/arm/ .
149+
150+
- name: Release
151+
run: |
152+
TIME="$(curl "https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" | jq -r .created_at)"
153+
154+
cat <<EOF | sed -E 's/^ //' >Release.md
155+
CI ${GITHUB_REF_NAME} $(date -d "${TIME}" -u +'%Y-%m-%d %H:%M:%S %Z(%:z)')
156+
157+
# ${GITHUB_REF_NAME}
158+
159+
$(date -d "${TIME}" -u +'%Y-%m-%d %H:%M:%S %Z(%:z)')
160+
161+
## Sources
162+
$(cat bin/targets/ipq50xx/arm/feeds.buildinfo | awk -F'[ ^]' '{print $2 ": `" $4 "`"}')
163+
164+
## SHA256
165+
$(cat bin/targets/ipq50xx/arm/sha256sums | awk '{printf "%s: `%s`\n", $2, $1}' | sed -E 's/^\*//')
166+
EOF
167+
168+
tag="ci-${GITHUB_REF_NAME}-$(date -d "${TIME}" -u +'%Y%m%d-%H%M%S-%Z')"
169+
hub release create -t "$GITHUB_SHA" "$tag" -F Release.md --prerelease \
170+
-a bin/targets/ipq50xx/arm/sha256sums \
171+
$(for a in bin/targets/ipq50xx/arm/*.*; do echo -a "$a"; done) \
172+
$(for a in *.tar; do echo -a "$a"; done)
173+
env:
174+
GITHUB_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)