-
Notifications
You must be signed in to change notification settings - Fork 11
188 lines (160 loc) · 6 KB
/
build.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: RisingOS Builder
on:
workflow_dispatch:
inputs:
BRAND:
description: 'Put your device manufacturer name please.'
required: true
CODENAME:
description: 'Put your device codename please.'
required: true
SIGNING:
description: 'The build signing. Set to "normal" by default.'
required: true
default: 'normal'
type: choice
options:
- 'full'
- 'normal'
- 'normal-fastboot'
TYPE:
description: 'The build type. Set to "userdebug" by default.'
required: true
default: 'userdebug'
type: choice
options:
- 'eng'
- 'user'
- 'userdebug'
RELEASE:
description: 'The build target. Set to "stable" by default.'
required: true
default: 'stable'
type: choice
options:
- 'test'
- 'stable'
VARIANT:
description: 'If you wanna build other variants like vanilla, core or gapps.'
required: false
default: 'CORE'
type: choice
options:
- 'VANILLA'
- 'CORE'
- 'GAPPS'
permissions:
actions: write
contents: write
statuses: write
run-name: "RisingOS Build for ${{ inputs.BRAND }} ${{ inputs.CODENAME }} [${{ inputs.TYPE }}, ${{ inputs.RELEASE }} & ${{ inputs.VARIANT }}]"
jobs:
check-limit:
runs-on: ubuntu-latest
outputs:
staging: ${{ steps.get_role.outputs.is_staging_member }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get User Role
id: get_role
env:
GH_TOKEN: ${{ secrets.TOKEN }}
run: |
OWNERS=$(gh api -H "Accept: application/vnd.github+json" /orgs/RisingOSS-devices/members?role=admin --jq '.[].login')
STAGING_MEMBERS=$(gh api -H "Accept: application/vnd.github+json" /orgs/RisingOS-staging/members --jq '.[].login')
DEVICES_MEMBERS=$(gh api -H "Accept: application/vnd.github+json" /orgs/RisingOSS-devices/members --jq '.[].login')
is_owner=$(echo "$OWNERS" | grep -q "${{ github.actor }}" && echo "true" || echo "false")
is_staging_member=$(echo "$STAGING_MEMBERS" | grep -q "${{ github.actor }}" && echo "true" || echo "false")
is_devices_member=$(echo "$DEVICES_MEMBERS" | grep -q "${{ github.actor }}" && echo "true" || echo "false")
echo "is_owner=$is_owner" >> $GITHUB_ENV
echo "is_staging_member=$is_staging_member" >> $GITHUB_ENV
echo "is_devices_member=$is_devices_member" >> $GITHUB_ENV
echo "is_owner=$is_owner" >> $GITHUB_OUTPUT
echo "is_staging_member=$is_staging_member" >> $GITHUB_OUTPUT
echo "is_devices_member=$is_devices_member" >> $GITHUB_OUTPUT
- name: Check Builds Limit
id: check_limit
run: |
COUNTER_FILE=".github/workflow_counter.json"
CURRENT_DATE=$(date +%Y-%m-%d)
DEVICE=${{ inputs.CODENAME }}
if [[ ! -f "$COUNTER_FILE" ]] || ! jq empty "$COUNTER_FILE" 2>/dev/null; then
echo '{}' > "$COUNTER_FILE"
fi
TODAY_RUNS=$(jq -r --arg device "$DEVICE" --arg date "$CURRENT_DATE" \
'if .[$device][$date] then .[$device][$date] else 0 end' "$COUNTER_FILE")
if [[ ! "$TODAY_RUNS" =~ ^[0-9]+$ ]]; then
TODAY_RUNS=0
fi
echo "Today's runs for device $DEVICE: $TODAY_RUNS"
if [[ "${{ env.is_owner }}" == "true" ]]; then
LIMIT=-1
elif [[ "${{ env.is_staging_member }}" == "true" ]]; then
LIMIT=5
else
LIMIT=3
fi
if [[ $LIMIT -ne -1 && "$TODAY_RUNS" -ge $LIMIT ]]; then
echo "Device $DEVICE has reached the daily limit of $LIMIT workflow runs."
exit 1
fi
NEW_RUNS=$((TODAY_RUNS + 1))
jq --arg device "$DEVICE" --arg date "$CURRENT_DATE" --argjson runs "$NEW_RUNS" \
'del(.[$device]) | .[$device][$date] = $runs' "$COUNTER_FILE" > tmp.json && mv tmp.json "$COUNTER_FILE"
echo "Updated run count for device $DEVICE: $NEW_RUNS"
- name: Commit and push counter update
run: |
COUNTER_FILE=".github/workflow_counter.json"
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add $COUNTER_FILE
git commit -m "Update workflow run count for device ${{ inputs.CODENAME }}"
git push
if: steps.check_limit.outcome == 'success'
build:
needs: check-limit
runs-on: self-hosted
env:
USER: sketu
BRAND: ${{ inputs.BRAND }}
CODENAME: ${{ inputs.CODENAME }}
SIGNING: ${{ inputs.SIGNING }}
TYPE: ${{ inputs.TYPE }}
RELEASE: ${{ inputs.RELEASE }}
VARIANT: ${{ inputs.VARIANT }}
STAGING: ${{ needs.check-limit.outputs.staging }}
SF_HOST: ${{ secrets.SF_HOST }}
SF_USERNAME: ${{ secrets.SF_USERNAME }}
SF_PASSWORD: ${{ secrets.SF_PASSWORD }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Init and Sync
run: bash resync.sh
- name: Clone Repositories
run: |
mkdir -p /home/sketu/rising/vendor/lineage-priv/
cp -r /home/sketu/keys /home/sketu/rising/vendor/lineage-priv/keys/
bash clone.sh
- name: Set flags
run: bash misc/flags.sh
- name: Build RisingOS
run: bash build.sh
- name: Upload Error Log
if: failure()
uses: actions/upload-artifact@v4
with:
name: error-log
path: /home/sketu/rising/out/error.log
- name: Upload Build JSON
if: success()
uses: actions/upload-artifact@v4
with:
name: build-json
path: /home/sketu/rising/out/target/product/*/*${{ inputs.CODENAME }}.json
- name: Upload Build Files
run: bash upload.sh
- name: Post-Cleanup
if: ${{ always() }}
run: bash clean.sh