Skip to content

⏱️ Schedule Matrix Builds πŸ“ˆ #2405

⏱️ Schedule Matrix Builds πŸ“ˆ

⏱️ Schedule Matrix Builds πŸ“ˆ #2405

name: ⏱️ Schedule Matrix Builds πŸ“ˆ
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
on:
workflow_dispatch:
schedule:
- cron: "0 */3 * * *"
jobs:
pre-trigger-build:
runs-on: ubuntu-latest
permissions:
actions: write
contents: write
statuses: write
outputs:
build_list: ${{ steps.set-inputs.outputs.build_list }}
steps:
- name: Sync Lists
timeout-minutes: 15
env:
GH_TOKEN: "${{ github.token }}"
run: |
##presets
set +x ; set +e
#-------------#
###Trigger
gh workflow run "sync_lists.yaml" \
--repo "${GITHUB_REPOSITORY}" \
--ref "${GITHUB_REF}"
sleep 5
##Get ID
RUN_ID=""
while [[ -z "${RUN_ID}" ]]; do
RUN_ID="$(gh run list --repo "${GITHUB_REPOSITORY}" --workflow "sync_lists.yaml" --json 'databaseId' --jq '.[0].databaseId' 2>/dev/null | tr -d '[:space:]')"
sleep 5
done
gh run list --repo "${GITHUB_REPOSITORY}" --workflow "sync_lists.yaml"
##Wait
while true; do
STATUS="$(gh run view "${RUN_ID}" --repo "${GITHUB_REPOSITORY}" --json status --jq '.status' | tr -d '[:space:]')"
if [[ "${STATUS}" == "completed" ]]; then
break
fi
sleep 10
done
gh run list --repo "${GITHUB_REPOSITORY}" --workflow "sync_lists.yaml"
continue-on-error: false
- name: Checkout repository
uses: actions/checkout@v4
with:
path: main
fetch-depth: 1
filter: "blob:none"
- name: Setup Env
run: |
##presets
set +x ; set +e
#-------------#
##CoreUtils
sudo apt update -y -qq
sudo apt install bc coreutils curl dos2unix fdupes jq moreutils wget -y -qq
#-------------#
##Host
HOST_TRIPLET="$(uname -m)-$(uname -s)"
echo "HOST_TRIPLET=${HOST_TRIPLET}" >> "${GITHUB_ENV}"
#-------------#
##Repo
PKG_REPO="${GITHUB_REPOSITORY}"
echo "PKG_REPO=${PKG_REPO#*/}" >> "${GITHUB_ENV}"
#-------------#
##tmp
SYSTMP="$(dirname $(mktemp -u))" && export SYSTMP="${SYSTMP}"
echo "SYSTMP=${SYSTMP}" >> "${GITHUB_ENV}"
#-------------#
mkdir -p "${HOME}/bin"
sudo apt update -y
sudo apt install dos2unix -y
continue-on-error: true
- name: Get & Set Inputs
id: set-inputs
run: |
##presets
set +x ; set +e
#-------------#
##Get Data
mkdir -pv "${SYSTMP}/TEMP"
pushd "$(mktemp -d)" &>/dev/null
curl -qfsSL "https://raw.githubusercontent.com/pkgforge-cargo/builder/refs/heads/main/data/BUILD_LIST.txt" | head -n 256 | sort -u | sed -E 's/^[[:space:]]+|[[:space:]]+$//g' | jq -R '{target: "ALL", crate: .}' > "${SYSTMP}/TEMP/BUILD_LIST.json"
cat "${SYSTMP}/TEMP/BUILD_LIST.json" | jq -s 'sort_by(.crate)' > "${SYSTMP}/TEMP/LIST.json"
##Set Input (256 builds)
BUILD_LIST="$(jq -c '[.[]] | .[:256]' "${SYSTMP}/TEMP/LIST.json")"
echo "${BUILD_LIST}" | jq -r '.[] | .crate' | sort -u >> "${GITHUB_WORKSPACE}/main/data/QUEUE_LIST.txt"
sort -u "${GITHUB_WORKSPACE}/main/data/QUEUE_LIST.txt" -o "${GITHUB_WORKSPACE}/main/data/QUEUE_LIST.txt"
sed -E 's/^[[:space:]]+|[[:space:]]+$//g' -i "${GITHUB_WORKSPACE}/main/data/QUEUE_LIST.txt"
##Validate Input
if ! echo "${BUILD_LIST}" | jq -e 'type == "array" and length > 0' >/dev/null; then
echo -e "\n[-] Input Json is likely Invalid\n"
echo "${BUILD_LIST}" | jq .
exit 1
else
ESCAPED_BUILD_LIST=$(echo "$BUILD_LIST" | jq -c .)
echo "build_list=${ESCAPED_BUILD_LIST}" >> "${GITHUB_OUTPUT}"
fi
popd &>/dev/null
continue-on-error: false
- name: Sanity Check Input JSON
run: |
echo '${{ steps.set-inputs.outputs.build_list }}' | jq .
continue-on-error: true
- name: Get DateTime
run: |
#Presets
set +x ; set +e
#--------------#
NEPALI_TIME="$(TZ='Asia/Kathmandu' date +'%Y-%m-%d (%I:%M:%S %p)')"
echo "NEPALI_TIME=${NEPALI_TIME}" >> "${GITHUB_ENV}"
continue-on-error: true
- name: Pull & Push
run: |
#Presets
set +x ; set +e
#--------------#
cd "${GITHUB_WORKSPACE}/main"
echo "GIT_TERMINAL_PROMPT=0" >> "${GITHUB_ENV}"
echo "GIT_ASKPASS=/bin/echo" >> "${GITHUB_ENV}"
git config --global "user.email" "AjamX101@gmail.com"
git config --global "user.name" "Azathothas"
git pull origin main --no-edit 2>/dev/null
git pull origin main --ff-only ; git merge --no-ff -m "Merge & Sync"
continue-on-error: true
- uses: stefanzweifel/git-auto-commit-action@v6
with:
repository: ./main
commit_user_name: Azathothas
commit_user_email: AjamX101@gmail.com
commit_message: "♻️ Updated QueList πŸ“¦ <-- [${{ env.NEPALI_TIME }}] ⌚"
trigger-build:
needs: [pre-trigger-build]
runs-on: ubuntu-latest
timeout-minutes: 250
permissions:
actions: write
contents: read
statuses: write
strategy:
fail-fast: false
max-parallel: 10
matrix:
package: ${{ fromJSON(needs.pre-trigger-build.outputs.build_list) }}
steps:
- name: Current Package
run: |
echo '${{ toJSON(matrix.package) }}' | jq -r '
"Target: \(.target)",
"Crate: \(.crate)"
'
continue-on-error: true
- name: Trigger Matrix Builds
if: ${{ toJson(matrix.package) != '{}' }}
env:
GH_TOKEN: "${{ github.token }}"
run: |
##presets
set +x ; set +e
#-------------#
gh workflow run "matrix_builds.yaml" \
--repo "${GITHUB_REPOSITORY}" \
--ref "${GITHUB_REF}" \
-f target="ALL" \
-f crate-name="${{ matrix.package.crate }}" \
-f debug="false" \
-f logs="true" \
-f rebuild="true"
continue-on-error: false