forked from WLAN-Pi/pi-gen
-
Notifications
You must be signed in to change notification settings - Fork 0
141 lines (119 loc) · 4.06 KB
/
build-image.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
134
135
136
137
138
139
140
141
name: Build image
on:
# Allow manual runs of workflow from Actions tab
workflow_dispatch:
inputs:
version-bump:
description: Version bump
required: true
type: choice
options:
- Auto
- Major
- Minor
- Patch
- RC
- Dev
- Release
default: Auto
# schedule:
# - cron: '37 5 * * *'
push:
branches:
- force-build
- rg-dev
- rg-release
jobs:
build:
runs-on: "${{ vars.RUNS_ON || 'ubuntu-22.04' }}"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Prepare docker output
run: |
touch output.env
- name: Build image
id: build-image
run: |
last_commit_date=$(git log -1 --format=%cd --date=unix)
last_day=$(date -d '-1 day' +%s)
if [ "${last_commit_date}" -lt "${last_day}" ]; then
echo "Nothig new to build."
echo "Last commit:"
git log -1 --format='%C(auto)%h (%cd) - %s' --date=relative
exit 0
fi
sudo docker run --rm --privileged \
multiarch/qemu-user-static --reset -p yes
sudo -E ./build-docker.sh -v ${{ github.workspace }}/output.env:/output.env
env:
FIRST_USER_NAME: ${{ vars.FIRST_USER_NAME }}
FIRST_USER_PASS: ${{ vars.FIRST_USER_PASS }}
- name: Load and export docker output
run: |
while IFS='=' read -r key value; do
echo "Processing $key with value $value"
echo "$key=$value" >> $GITHUB_ENV
done < output.env
echo "All variables from output.env have been added to GITHUB_ENV."
- name: Generate checksum
id: generate-checksum
run: |
cd deploy; for file in *.zip; do sha256sum --binary $file | sudo tee "${file}.sha256"; done; cd ../
- name: Get current date
id: date
run: echo "date=$(date -u +'%Y%m%d')" >> $GITHUB_ENV
- name: Set nightly artifact name
id: set-nightly-artifact-name
run: echo "ARTIFACT_NAME=wlanpi-nightly-${{ env.version }}~gha${{ env.date }}" >> $GITHUB_ENV
- name: Upload image
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: deploy/*.zip
- name: Upload zipped image checksum
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}-sha256
path: deploy/*.sha256
- name: Upload image info
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}-info
path: deploy/*.info
- name: Create pre-release from default branch
if: ${{ github.event.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.event.ref == format('refs/heads/{0}', 'rg-release') }}
uses: "joshschmelzle/action-automatic-releases@1c60c2dcfeb5382b81099310bdb4a376dc7753a0"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: ${{ env.version }}
prerelease: true
files: |
deploy/*.zip
deploy/*.info
deploy/rg-wlanpi-os/os.json
deploy/*.sha256
- name: Upload logs
if: always()
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}-buildlogs
path: deploy/*.log
- name: Chown the dir for next time
if: always()
run: |
sudo chown -R ubuntu:ubuntu ./*
slack-workflow-status:
if: ${{ always() && (github.repository_owner == 'WLAN-Pi') && (! github.event.pull_request.head.repo.fork) }}
name: Post Workflow Status to WLAN-Pi Slack
needs:
- build
runs-on: "${{ vars.RUNS_ON || 'ubuntu-22.04' }}"
steps:
- name: Slack Workflow Notification
uses: Gamesight/slack-workflow-status@master
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}