Skip to content

Nightly maintenance workflow #280

Nightly maintenance workflow

Nightly maintenance workflow #280

Workflow file for this run

name: Maintenance
run-name: "Nightly maintenance workflow"
on:
workflow_dispatch:
schedule:
- cron: '17 4 * * *'
permissions:
contents: write
issues: write
pull-requests: write
jobs:
RetrieveTargetsMatrix:
if: github.repository == 'XANTH-IO/stm32-cmake'
uses: ./.github/workflows/create-matrix.yml
CreateFamilyLabel:
if: github.repository == 'XANTH-IO/stm32-cmake'
needs: RetrieveTargetsMatrix
strategy:
matrix: ${{ fromJSON(needs.RetrieveTargetsMatrix.outputs.matrix) }}
fail-fast: false
uses: ./.github/workflows/create-label.yml
with:
labelname: ${{ matrix.family }}
color: "FFD200"
CreateProjectManagementLabel:
if: github.repository == 'XANTH-IO/stm32-cmake'
strategy:
matrix:
label: [ missing-devices, dependency-update ]
fail-fast: false
uses: ./.github/workflows/create-label.yml
with:
labelname: ${{ matrix.label }}
color: "03234B"
UpdateFamilyWithLatestSTReposTags:
if: github.repository == 'XANTH-IO/stm32-cmake'
runs-on: ubuntu-latest
needs: [RetrieveTargetsMatrix, CreateFamilyLabel, CreateProjectManagementLabel]
strategy:
matrix: ${{ fromJSON(needs.RetrieveTargetsMatrix.outputs.matrix) }}
fail-fast: false
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Print Job
run: echo "Updating ${{ matrix.family }} Family with latest ST tags"
- name: Prepare Env variables
id: prepare_env
run: |
family_src_file=${GITHUB_WORKSPACE}/$(grep -lr -E "stm32_util_create_family_targets\(\s?${{ matrix.family }}(\s\w+)?\)" cmake/stm32/)
family_l=$(echo "${{ matrix.family }}" | tr '[:upper:]' '[:lower:]')
cube=$(sed -nr "s/set\(CUBE_${{ matrix.family }}_URL\s+(.*)\)/\1/p" ${family_src_file})
if [[ -z ${cube} ]]; then
cube="STMicroelectronics/STM32Cube${{ matrix.family }}"
else
cube="$(echo ${cube} | sed -rn 's@((https?://)?github\.com/)?(.*)@\3@p')"
fi
cmsis=$(sed -nr "s/set\(CMSIS_${{ matrix.family }}_URL\s+(.*)\)/\1/p" ${family_src_file})
if [[ -z ${cmsis} ]]; then
cmsis="STMicroelectronics/cmsis_device_${family_l}"
else
cmsis="$(echo ${cmsis} | sed -rn 's@((https?://)?github\.com/)?(.*)@\3@p')"
fi
hal=$(sed -nr "s/set\(HAL_${{ matrix.family }}_URL\s+(.*)\)/\1/p" ${family_src_file})
if [[ -z ${hal} ]]; then
hal="STMicroelectronics/stm32${family_l}xx_hal_driver"
else
hal="$(echo ${hal} | sed -rn 's@((https?://)?github\.com/)?(.*)@\3@p')"
fi
{
echo "FAMILY_SRC_FILE=${family_src_file}"
echo "CUBE_REPO=${cube}"
echo "CMSIS_REPO=${cmsis}"
echo "HAL_REPO=${hal}"
} >> $GITHUB_OUTPUT
- name: Get Cube version
id: get-latest-cube
if: ${{ steps.prepare_env.outputs.CUBE_REPO }}
uses: './.github/actions/getLatestTag'
with:
repository: ${{ steps.prepare_env.outputs.CUBE_REPO }}
- name: Get CMSIS version
id: get-latest-cmsis
if: ${{ steps.prepare_env.outputs.CMSIS_REPO }}
uses: './.github/actions/getLatestTag'
with:
repository: ${{ steps.prepare_env.outputs.CMSIS_REPO }}
- name: Get HAL version
id: get-latest-hal
if: ${{ steps.prepare_env.outputs.HAL_REPO }}
uses: './.github/actions/getLatestTag'
with:
repository: ${{ steps.prepare_env.outputs.HAL_REPO }}
- name: Update Cube with latest version
if: ${{ steps.get-latest-cube.outputs.TAG }}
env:
FAMILY_SRC_FILE: ${{ steps.prepare_env.outputs.FAMILY_SRC_FILE }}
run:
sed -ri 's@(set\(CUBE_${{ matrix.family }}_VERSION(\s+))(.*)(\))@\1${{ steps.get-latest-cube.outputs.TAG }}\4@g' ${FAMILY_SRC_FILE}
- name: Update CMSIS with latest version
if: ${{ steps.get-latest-cmsis.outputs.TAG }}
env:
FAMILY_SRC_FILE: ${{ steps.prepare_env.outputs.FAMILY_SRC_FILE }}
run:
sed -ri 's@(set\(CMSIS_${{ matrix.family }}_VERSION(\s+))(.*)(\))@\1${{ steps.get-latest-cmsis.outputs.TAG }}\4@g' ${FAMILY_SRC_FILE}
- name: Update HAL with latest version
if: ${{ steps.get-latest-hal.outputs.TAG }}
env:
FAMILY_SRC_FILE: ${{ steps.prepare_env.outputs.FAMILY_SRC_FILE }}
run:
sed -ri 's@(set\(HAL_${{ matrix.family }}_VERSION(\s+))(.*)(\))@\1${{ steps.get-latest-hal.outputs.TAG }}\4@g' ${FAMILY_SRC_FILE}
- name: Generate token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
id: generate-token
- name: Create Dependancy update Pull Request
uses: peter-evans/create-pull-request@v6
with:
add-paths: cmake/stm32/
commit-message: Update ${{ matrix.family }} dependencies
branch: maintenance/${{ matrix.family }}-dependencies-update
delete-branch: true
title: Update ${{ matrix.family }} dependencies
labels: dependency-update, ${{ matrix.family }}
token: ${{ steps.generate-token.outputs.token }}
body: |
Update ${{ matrix.family }} to use latest ST Repos
CheckForMissingDevices:
if: github.repository == 'XANTH-IO/stm32-cmake'
runs-on: ubuntu-latest
needs: [RetrieveTargetsMatrix, CreateFamilyLabel, CreateProjectManagementLabel]
strategy:
matrix: ${{ fromJSON(needs.RetrieveTargetsMatrix.outputs.matrix) }}
fail-fast: false
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Print Job
run: echo "Looking for possible missing ${{ matrix.family }} devices"
- name: Prepare Env variables
id: prepare-env
run: |
FAMILY_L=$(echo "${{ matrix.family }}" | tr '[:upper:]' '[:lower:]')
family_src_file=${GITHUB_WORKSPACE}/$(grep -lr -E "stm32_util_create_family_targets\(\s?${{ matrix.family }}(\s\w+)?\)" cmake/stm32/)
{
echo "FAMILY_L=${FAMILY_L}"
echo "FAMILY_SRC_FILE=${family_src_file}"
} >> $GITHUB_OUTPUT
- name: Get serie from family file
id: get-ss-id-from-file
env:
FAMILY_SRC_FILE: ${{ steps.prepare-env.outputs.FAMILY_SRC_FILE }}
run: |
serie=($(sed -rn "s@#\s+SERIE\s+(SS[0-9]{4,})@\1@p" ${FAMILY_SRC_FILE} | tr -d '\r'))
echo "SERIE=${serie[@]}" >> $GITHUB_OUTPUT
- name: Get Serie (Family) number from ST website
id: get-ss-id-from-st
env:
FAMILY_L: ${{ steps.prepare-env.outputs.FAMILY_L }}
if: ${{ ! steps.get-ss-id-from-file.outputs.SERIE }}
run: |
URL=https://www.st.com/en/microcontrollers-microprocessors/stm32${FAMILY_L}-series.html
serie=$(curl ${URL} --compressed -H 'User-Agent: Firefox/9000' \
| sed -rne "s@(.*)(data-associated-to=\")(SS[0-9]{4,})(\".*)@\3@p")
if [ -n ${serie} ]; then
echo "SERIE=$serie" >> $GITHUB_OUTPUT
fi
- name: Retrieve Serie (Family) JSONs
id: retrieve-jsons
continue-on-error: true
if: ${{ steps.get-ss-id-from-st.outputs.SERIE || steps.get-ss-id-from-file.outputs.SERIE }}
env:
SERIE_ST: ${{ steps.get-ss-id-from-st.outputs.SERIE }}
SERIE_FILE: ${{ steps.get-ss-id-from-file.outputs.SERIE }}
run: |
SERIES=(${SERIE_ST} ${SERIE_FILE})
mkdir -p .series
for serie in ${SERIES[@]}; do
URL=https://www.st.com/bin/st/selectors/cxst/en.cxst-ps-grid.html/${serie}.json
echo "Retrieving ${URL}"
curl ${URL} --compressed -H 'User-Agent: Firefox/9000' -o .series/${serie}.json
done
- name: Get existing devices list
id: get-devices-list
if: ${{ steps.retrieve-jsons.outcome == 'success' }}
run: |
{
echo "DEVICES<<EOF"
jq -r '.rows[].cells[0].value' .series/*.json | sort
echo "EOF"
} >> $GITHUB_OUTPUT
rm -rf .series
- name: Get unsupported (yet) devices list
id: get-unsupported-list
if: ${{ steps.get-devices-list.outputs.DEVICES }}
env:
FAMILY_SRC_FILE: ${{ steps.prepare-env.outputs.FAMILY_SRC_FILE }}
DEVICES: ${{ steps.get-devices-list.outputs.DEVICES }}
run: |
MISSINGS=(${DEVICES})
for dev in ${DEVICES}; do
d=${dev#*STM32}
if [ -z $(sed -rn "s@(\s+)(${d})@X@p" ${FAMILY_SRC_FILE}) ]; then
echo "Device ${dev} is not supported"
else
echo "Device ${dev} is already supported"
for i in "${!MISSINGS[@]}"; do
if [[ ${MISSINGS[i]} = ${dev} ]]; then
unset 'MISSINGS[i]'
fi
done
fi
done
if [ 0 -ne ${#MISSINGS[@]} ]; then
echo "MISSINGS=${MISSINGS[@]}" >> $GITHUB_OUTPUT
fi
- name: Check for existing Issue
id: get-issue-number
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LABELS: ${{ matrix.family }},missing-devices
run: |
existing=$(gh issue list \
--label "${LABELS}" \
--state open \
--json number \
--jq '.[0].number')
if [ -n ${existing} ]; then
echo "ISSUE=${existing}" >> $GITHUB_OUTPUT
fi
- name: Open an issue for missing devices
if: ${{ steps.get-unsupported-list.outputs.MISSINGS && ! steps.get-issue-number.outputs.ISSUE }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LABELS: ${{ matrix.family }},missing-devices
MISSINGS: ${{ steps.get-unsupported-list.outputs.MISSINGS }}
run: |
echo "Creating issue to report missing devices"
{
echo "Not supported yet devices list:"
for device in ${MISSINGS[@]}; do
echo "- [ ] ${device}"
done
} >> body.file
gh issue create \
--title "${{ matrix.family }} has devices not supported" \
--label "${LABELS}" \
--body-file body.file
- name: Close the issue as there are no missing devices anymore
if: ${{ steps.get-devices-list.outputs.DEVICES && ! steps.get-unsupported-list.outputs.MISSINGS && steps.get-issue-number.outputs.ISSUE }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE: ${{ steps.get-issue-number.outputs.ISSUE }}
run: |
echo "Closing existing issue ${ISSUE}"
gh issue close "${ISSUE}" \
--comment "${{ matrix.family }} has all its devices supported now"