Skip to content

Commit dc0c379

Browse files
Add a workflow to update the bricks file automatically (#42)
1 parent b5c4045 commit dc0c379

File tree

2 files changed

+73
-1
lines changed

2 files changed

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

Taskfile.dist.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tasks:
44
init:ci:
55
desc: Initialize CI environment
66
cmds:
7-
- pip install libs/arduino_app_bricks-0.6.1-py3-none-any.whl reuse pip-licenses
7+
- pip install libs/arduino_app_bricks-*-py3-none-any.whl reuse pip-licenses
88

99
license:
1010
deps:

0 commit comments

Comments
 (0)