1+ name : Update bricks whl file to the latest version
2+ on :
3+ workflow_dispatch :
4+ schedule :
5+ # Run every day at 8:00 AM UTC
6+ - cron : ' 0 8 * * *'
7+ pull_request :
8+ permissions :
9+ contents : write
10+ pull-requests : write
11+
12+ jobs :
13+ steps :
14+ runs-on : ubuntu-latest
15+ steps :
16+ - name : Checkout repository
17+ uses : actions/checkout@v4
18+
19+ - name : Get latest bricks version
20+ id : get-latest-version
21+ run : |
22+ LATEST_RELEASE=$(curl -s https://api.github.com/repos/arduino/app-bricks-py/releases/latest | jq -r .tag_name | sed 's/^release\///')
23+ echo "LATEST_RELEASE=$LATEST_RELEASE" >> $GITHUB_OUTPUT
24+
25+ - name : Check if there is an existing branch for the latest version
26+ id : check-branch
27+ run : |
28+ LATEST_RELEASE=${{ steps.get-latest-version.outputs.LATEST_RELEASE }}
29+ if git ls-remote --heads origin update-bricks-${LATEST_RELEASE} | grep -q update-bricks-${LATEST_RELEASE}; then
30+ echo "Branch update-bricks-${LATEST_RELEASE} already exists."
31+ echo "branch_exists=true" >> $GITHUB_OUTPUT
32+ fi
33+
34+ - name : Check if current version is up to date
35+ if : steps.check-branch.outputs.branch_exists != 'true'
36+ id : check-update
37+ run : |
38+ LATEST_RELEASE=${{ steps.get-latest-version.outputs.LATEST_RELEASE }}
39+ if ls libs/arduino_app_bricks-*.whl 1> /dev/null 2>&1; then
40+ CURRENT_VERSION=$(ls libs/arduino_app_bricks-*.whl | sed -E 's/.*arduino_app_bricks-([0-9]+\.[0-9]+\.[0-9]+)-py3-none-any\.whl/\1/')
41+ echo "CURRENT_VERSION=$CURRENT_VERSION"
42+ if [ "$CURRENT_VERSION" = "$LATEST_RELEASE" ]; then
43+ echo "No update needed. Current version is up to date."
44+ echo "update_needed=false" >> $GITHUB_OUTPUT
45+ exit 0
46+ fi
47+ fi
48+ echo "Update needed. Current version is outdated or not present."
49+
50+ - name : Download whl file
51+ if : steps.check-branch.outputs.branch_exists != 'true' && steps.check-update.outputs.update_needed != 'false'
52+ run : |
53+ LATEST_RELEASE=${{ steps.get-latest-version.outputs.LATEST_RELEASE }}
54+ ASSET_URL=$(curl -s https://api.github.com/repos/arduino/app-bricks-py/releases/latest | jq -r '.assets[] | select(.name | endswith(".whl")) | .browser_download_url')
55+ wget "$ASSET_URL" -O libs/arduino_app_bricks-${LATEST_RELEASE}-py3-none-any.whl
56+
57+ - name : Remove old whl files
58+ if : steps.check-branch.outputs.branch_exists != 'true' && steps.check-update.outputs.update_needed != 'false'
59+ run : |
60+ LATEST_RELEASE=${{ steps.get-latest-version.outputs.LATEST_RELEASE }}
61+ find libs/ -name 'arduino_app_bricks-*.whl' ! -name "arduino_app_bricks-${LATEST_RELEASE}-py3-none-any.whl" -delete
62+
63+ - name : Create Pull Request
64+ if : steps.check-branch.outputs.branch_exists != 'true' && steps.check-update.outputs.update_needed != 'false'
65+ uses : peter-evans/create-pull-request@v5
66+ with :
67+ base : main
68+ branch : update-bricks-${{ steps.get-latest-version.outputs.LATEST_RELEASE }}
69+ title : " Update bricks whl file to ${{ steps.get-latest-version.outputs.LATEST_RELEASE }}"
70+ body : " This PR updates the Arduino App Bricks wheel file to the latest version ${{ steps.get-latest-version.outputs.LATEST_RELEASE }}."
71+ commit-message : " Update bricks whl to ${{ steps.get-latest-version.outputs.LATEST_RELEASE }}"
72+ add-paths : |
73+ libs/arduino_app_bricks-*.whl
0 commit comments