Skip to content

Commit 59134ad

Browse files
committed
Use GHA to build
1 parent f552507 commit 59134ad

File tree

1 file changed

+176
-0
lines changed

1 file changed

+176
-0
lines changed

.github/workflows/ci.yml

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

0 commit comments

Comments
 (0)