Skip to content

Commit 58f3ab8

Browse files
authored
Create r3g-openwrt
1 parent 174bb05 commit 58f3ab8

1 file changed

Lines changed: 187 additions & 0 deletions

File tree

.github/workflows/r3g-openwrt

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
#
2+
# Copyright (c) 2019-2020 P3TERX <https://p3terx.com>
3+
#
4+
# This is free software, licensed under the MIT License.
5+
# See /LICENSE for more information.
6+
#
7+
# https://github.com/P3TERX/Actions-OpenWrt
8+
# Description: Build OpenWrt using GitHub Actions
9+
#
10+
11+
name: Build Mi r3g1 OpenWrt
12+
13+
on:
14+
repository_dispatch:
15+
workflow_dispatch:
16+
inputs:
17+
ssh:
18+
description: 'SSH connection to Actions'
19+
required: true
20+
default: 'false'
21+
schedule:
22+
- cron: 0 18 * * *
23+
# watch:
24+
# types: started
25+
26+
env:
27+
REPO_URL: https://github.com/openwrt/openwrt
28+
REPO_BRANCH: master
29+
FEEDS_CONF: feeds.conf.default
30+
CONFIG_FILE: config/r3g1.config
31+
DIY_P1_SH: diy-part1.sh
32+
DIY_P2_SH: diy-part2.sh
33+
UPLOAD_BIN_DIR: true
34+
UPLOAD_FIRMWARE: true
35+
UPLOAD_COWTRANSFER: true
36+
UPLOAD_WETRANSFER: true
37+
UPLOAD_RELEASE: false
38+
TZ: Asia/Shanghai
39+
40+
jobs:
41+
build:
42+
runs-on: ubuntu-18.04
43+
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@main
47+
48+
- name: Initialization environment
49+
env:
50+
DEBIAN_FRONTEND: noninteractive
51+
run: |
52+
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc
53+
sudo -E apt-get -qq update
54+
sudo -E apt-get -qq install $(curl -fsSL git.io/depends-ubuntu-1804)
55+
sudo -E apt-get -qq autoremove --purge
56+
sudo -E apt-get -qq clean
57+
sudo timedatectl set-timezone "$TZ"
58+
sudo mkdir -p /workdir
59+
sudo chown $USER:$GROUPS /workdir
60+
- name: Clone source code
61+
working-directory: /workdir
62+
run: |
63+
df -hT $PWD
64+
git clone $REPO_URL -b $REPO_BRANCH openwrt
65+
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt
66+
- name: Load custom feeds
67+
run: |
68+
[ -e $FEEDS_CONF ] && mv $FEEDS_CONF openwrt/feeds.conf.default
69+
chmod +x $DIY_P1_SH
70+
cd openwrt
71+
$GITHUB_WORKSPACE/$DIY_P1_SH
72+
- name: Update feeds
73+
run: cd openwrt && ./scripts/feeds update -a
74+
75+
- name: Install feeds
76+
run: cd openwrt && ./scripts/feeds install -a
77+
78+
- name: Load custom configuration
79+
run: |
80+
[ -e files ] && mv files openwrt/files
81+
[ -e $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config
82+
chmod +x $DIY_P2_SH
83+
cd openwrt
84+
$GITHUB_WORKSPACE/$DIY_P2_SH
85+
- name: SSH connection to Actions
86+
uses: P3TERX/ssh2actions@v1.0.0
87+
if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh')
88+
env:
89+
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
90+
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
91+
92+
- name: Download package
93+
id: package
94+
run: |
95+
cd openwrt
96+
make defconfig
97+
make download -j8
98+
find dl -size -1024c -exec ls -l {} \;
99+
find dl -size -1024c -exec rm -f {} \;
100+
- name: Compile the firmware
101+
id: compile
102+
run: |
103+
cd openwrt
104+
echo -e "$(nproc) thread compile"
105+
make -j$(nproc) || make -j2 || make -j2 V=s
106+
echo "::set-output name=status::success"
107+
grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/' > DEVICE_NAME
108+
[ -s DEVICE_NAME ] && echo "DEVICE_NAME=_$(cat DEVICE_NAME)" >> $GITHUB_ENV
109+
echo "FILE_DATE=_$(date +"%Y%m%d%H%M")" >> $GITHUB_ENV
110+
- name: Check space usage
111+
if: (!cancelled())
112+
run: df -hT
113+
114+
- name: Upload bin directory
115+
uses: actions/upload-artifact@main
116+
if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true'
117+
with:
118+
name: OpenWrt_bin${{ env.DEVICE_NAME }}${{ env.FILE_DATE }}
119+
path: openwrt/bin
120+
121+
- name: Organize files
122+
id: organize
123+
if: env.UPLOAD_FIRMWARE == 'true' && !cancelled()
124+
run: |
125+
cd openwrt/bin/targets/*/*
126+
rm -rf packages
127+
echo "FIRMWARE=$PWD" >> $GITHUB_ENV
128+
echo "::set-output name=status::success"
129+
- name: Upload firmware directory
130+
uses: actions/upload-artifact@main
131+
if: steps.organize.outputs.status == 'success' && !cancelled()
132+
with:
133+
name: OpenWrt_firmware${{ env.DEVICE_NAME }}${{ env.FILE_DATE }}
134+
path: ${{ env.FIRMWARE }}
135+
136+
- name: Upload firmware to cowtransfer
137+
id: cowtransfer
138+
if: steps.organize.outputs.status == 'success' && env.UPLOAD_COWTRANSFER == 'true' && !cancelled()
139+
run: |
140+
curl -fsSL git.io/file-transfer | sh
141+
./transfer cow --block 2621440 -s -p 64 --no-progress ${FIRMWARE} 2>&1 | tee cowtransfer.log
142+
echo "::warning file=cowtransfer.com::$(cat cowtransfer.log | grep https)"
143+
echo "::set-output name=url::$(cat cowtransfer.log | grep https | cut -f3 -d" ")"
144+
145+
- name: Upload firmware to WeTransfer
146+
id: wetransfer
147+
if: steps.organize.outputs.status == 'success' && env.UPLOAD_WETRANSFER == 'true' && !cancelled()
148+
run: |
149+
curl -fsSL git.io/file-transfer | sh
150+
./transfer wet -s -p 16 --no-progress ${FIRMWARE} 2>&1 | tee wetransfer.log
151+
echo "::warning file=wetransfer.com::$(cat wetransfer.log | grep https)"
152+
echo "::set-output name=url::$(cat wetransfer.log | grep https | cut -f3 -d" ")"
153+
154+
- name: Generate release tag
155+
id: tag
156+
if: env.UPLOAD_RELEASE == 'true' && !cancelled()
157+
run: |
158+
echo "::set-output name=release_tag::$(date +"%Y.%m.%d-%H%M")"
159+
touch release.txt
160+
[ $UPLOAD_COWTRANSFER = true ] && echo "🔗 [Cowtransfer](${{ steps.cowtransfer.outputs.url }})" >> release.txt
161+
[ $UPLOAD_WETRANSFER = true ] && echo "🔗 [WeTransfer](${{ steps.wetransfer.outputs.url }})" >> release.txt
162+
echo "::set-output name=status::success"
163+
164+
- name: Upload firmware to release
165+
uses: softprops/action-gh-release@v1
166+
if: steps.tag.outputs.status == 'success' && !cancelled()
167+
env:
168+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
169+
with:
170+
tag_name: ${{ steps.tag.outputs.release_tag }}
171+
body_path: release.txt
172+
files: ${{ env.FIRMWARE }}/*
173+
174+
- name: Delete workflow runs
175+
uses: GitRML/delete-workflow-runs@main
176+
with:
177+
retain_days: 1
178+
keep_minimum_runs: 3
179+
180+
- name: Remove old Releases
181+
uses: dev-drprasad/delete-older-releases@v0.1.0
182+
if: env.UPLOAD_RELEASE == 'true' && !cancelled()
183+
with:
184+
keep_latest: 7
185+
delete_tags: true
186+
env:
187+
GITHUB_TOKEN: ${{ secrets.TOKEN }}

0 commit comments

Comments
 (0)