-
-
Notifications
You must be signed in to change notification settings - Fork 10
133 lines (120 loc) · 4.84 KB
/
snapshot.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
124
125
126
127
128
129
130
131
132
133
# thinRoot Snapshot build
# yamllint disable rule:truthy
---
name: Snapshot Build
on:
schedule:
- cron: '0 0 * * *' # run at 0 AM UTC
workflow_dispatch:
inputs:
skip_build:
description: 'Skip build (for testing workflow)?'
required: true
default: "false"
# default read-only permission
permissions:
contents: read
jobs:
repo-check:
name: Check for Changes
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- id: commit-check
run: echo "has-commits=$(git --no-pager log --pretty='format:%an' --since='24 hours ago' | grep -v github-actions | wc -l)" >> $GITHUB_OUTPUT
outputs:
has-commits: ${{ steps.commit-check.outputs.has-commits }}
build:
permissions:
contents: write # actions/upload-artifact
name: Snapshot build [${{ matrix.platform }}]
if: ${{ github.repository == 'jens-maus/thinRoot' && (github.event_name != 'schedule' || needs.repo-check.outputs.has-commits > 0) }}
runs-on: self-hosted
needs: repo-check
timeout-minutes: 300
outputs:
build_datetime: ${{ steps.env.outputs.build_datetime }}
build_version: ${{ steps.env.outputs.build_version }}
strategy:
fail-fast: false
matrix:
platform: [generic-x86_64]
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Install Dependencies
run: |
if ! dpkg-query -l wget bc cpio rsync zip python3 file >/dev/null 2>&1; then
apt update
apt install -y --no-install-recommends wget bc cpio rsync zip python3 file
fi
if ! getent group | grep -q ^builder:; then groupadd -g 48 builder; fi
if ! getent passwd | grep -q ^builder:; then useradd -m -u 1003 -g 48 -G sudo builder; fi
if ! grep -q ^builder; then echo "builder ALL=(ALL:ALL) NOPASSWD: ALL" >>/etc/sudoers; fi
chown -R builder:builder /home/builder
- name: Setup Environment
id: env
run: |
echo "DATE=$(date +%Y%m%d)" >> $GITHUB_ENV
echo "VERSION=$(date +%Y%m%d)" >> $GITHUB_ENV
echo "GITHUB_SHA7=$(echo ${GITHUB_SHA::7})" >> $GITHUB_ENV
echo "FAKE_BUILD=${{ github.event.inputs.skip_build }}" >> $GITHUB_ENV
JLEVEL=0
if [[ -f /sys/fs/cgroup/cpu.max ]]; then # cgroups v2
CPU_QUOTA=$(cut -d ' ' -f1 /sys/fs/cgroup/cpu.max)
if [[ "${CPU_QUOTA}" != "max" ]]; then
CPU_PERIOD=$(cut -d ' ' -f2 /sys/fs/cgroup/cpu.max)
JLEVEL=$((CPU_QUOTA / CPU_PERIOD + 1))
fi
elif [[ -f /sys/fs/cgroup/cpu/cpu.cfs_quota_us ]]; then # cgroups v1
CPU_QUOTA=$(cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us)
if [[ "${CPU_QUOTA}" != "-1" ]]; then
CPU_PERIOD=$(cat /sys/fs/cgroup/cpu/cpu.cfs_period_us)
JLEVEL=$((CPU_QUOTA / CPU_PERIOD + 1))
fi
fi
echo "JLEVEL=${JLEVEL}" >> $GITHUB_ENV
echo "build_datetime=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT
echo "build_version=$(date +%Y%m%d)" >> $GITHUB_OUTPUT
# - name: remote debug tmate session
# uses: mxschmitt/action-tmate@v1
# if: matrix.platform == 'ova'
# major build step
- name: Build
timeout-minutes: 300
shell: bash
run: |
rm -rf release/thinroot-* buildroot-????.*
sudo -H -E -u builder nice -n 19 make DATE=${{ env.DATE }} BR2_DL_DIR=/mnt/download BR2_CCACHE_DIR=/mnt/ccache/${{ matrix.platform }} BR2_JLEVEL=${{ env.JLEVEL }} clean-all ${{ matrix.platform }}-release
# check linux kernel config consistency
- name: Check Linux Kconfig
run: |
sudo -H -E -u builder nice -n 19 make DATE=${{ env.DATE }} BR2_DL_DIR=/mnt/download BR2_CCACHE_DIR=/mnt/ccache/${{ matrix.platform }} BR2_JLEVEL=${{ env.JLEVEL }} PRODUCT=${{ matrix.platform }} linux-check-dotconfig
########################
# upload build artifacts
- name: Upload build artifact [generic-x86_64]
uses: actions/upload-artifact@v4
with:
path: release/thinroot-${{ env.VERSION }}-${{ matrix.platform }}.img*
name: thinroot-${{ env.VERSION }}-${{ env.GITHUB_SHA7 }}-${{ matrix.platform }}.img
continue-on-error: true
# cleanup
- name: Cleanup
run: |
make clean-all
rm -rf release/thinroot-* buildroot-????.*
cleanup:
permissions:
contents: write # c-hive/gha-remove-artifacts
packages: write # smartsquaregmbh/delete-old-packages
actions: write # c-hive/gha-remove-artifacts
name: Cleanup artifacts/packages
runs-on: ubuntu-22.04
steps:
- name: Remove old artifacts
uses: c-hive/[email protected]
with:
age: '2 months'
skip-tags: true
skip-recent: 15
continue-on-error: true