Skip to content

Commit 7832f56

Browse files
authored
Create my.yml
1 parent d3be4d5 commit 7832f56

File tree

1 file changed

+190
-0
lines changed

1 file changed

+190
-0
lines changed

.github/workflows/my.yml

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

0 commit comments

Comments
 (0)