RisingOS Build for xiaomi munch [user, stable & CORE] #59
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
if echo "$OWNERS" | grep -q "${{ github.actor }}"; then | |
echo "is_owner=true" >> $GITHUB_ENV | |
echo "is_owner=true" >> $GITHUB_OUTPUT | |
else | |
echo "is_owner=false" >> $GITHUB_ENV | |
echo "is_owner=false" >> $GITHUB_OUTPUT | |
fi | |
if echo "$STAGING_MEMBERS" | grep -q "${{ github.actor }}"; then | |
echo "is_staging_member=true" >> $GITHUB_ENV | |
echo "is_staging_member=true" >> $GITHUB_OUTPUT | |
else | |
echo "is_staging_member=false" >> $GITHUB_ENV | |
echo "is_staging_member=false" >> $GITHUB_OUTPUT | |
fi | |
if echo "$DEVICES_MEMBERS" | grep -q "${{ github.actor }}"; then | |
echo "is_devices_member=true" >> $GITHUB_ENV | |
echo "is_devices_member=true" >> $GITHUB_OUTPUT | |
else | |
echo "is_devices_member=false" >> $GITHUB_ENV | |
echo "is_devices_member=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Check Builds Limit | |
id: check_limit | |
run: | | |
COUNTER_FILE=".github/workflow_counter.json" | |
CURRENT_DATE=$(date +%Y-%m-%d) | |
USER=${{ github.actor }} | |
if [[ ! -f "$COUNTER_FILE" ]] || ! jq empty "$COUNTER_FILE" 2>/dev/null; then | |
echo '{}' > "$COUNTER_FILE" | |
fi | |
TODAY_RUNS=$(jq -r --arg user "$USER" --arg date "$CURRENT_DATE" \ | |
'if .[$user][$date] then .[$user][$date] else 0 end' "$COUNTER_FILE") | |
if [[ ! "$TODAY_RUNS" =~ ^[0-9]+$ ]]; then | |
TODAY_RUNS=0 | |
fi | |
echo "Today's runs: $TODAY_RUNS" | |
if [[ "${{ env.is_owner }}" == "true" && "${{ env.is_staging_member }}" == "false" ]]; then | |
LIMIT=-1 | |
elif [[ "${{ env.is_devices_member }}" == "true" && "${{ env.is_staging_member }}" == "true" ]]; then | |
LIMIT=5 | |
else | |
LIMIT=3 | |
fi | |
if [[ $LIMIT -ne -1 && "$TODAY_RUNS" -ge $LIMIT ]]; then | |
echo "User $USER has reached the daily limit of $LIMIT workflow runs." | |
exit 1 | |
fi | |
NEW_RUNS=$((TODAY_RUNS + 1)) | |
jq --arg user "$USER" --arg date "$CURRENT_DATE" --argjson runs "$NEW_RUNS" \ | |
'.[$user][$date] = $runs' "$COUNTER_FILE" > tmp.json && mv tmp.json "$COUNTER_FILE" | |
echo "Updated run count: $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 @${{ github.actor }}" | |
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 }} | |
PROJECT: ${{ secrets.PROJECT }} | |
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 |