|
| 1 | +name: Publish to PlatformIO |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [released] |
| 6 | + workflow_call: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + packages: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + pio-publish: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + name: Publish a new Release to PlatformIO |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-tags: true |
| 20 | + - uses: actions/setup-python@v5 |
| 21 | + with: |
| 22 | + python-version: "3.9" |
| 23 | + - name: Install PlatformIO Core |
| 24 | + run: | |
| 25 | + python -m pip install --upgrade pip |
| 26 | + pip install platformio |
| 27 | + - name: Install jq for handling JSON data |
| 28 | + run: | |
| 29 | + sudo apt update |
| 30 | + sudo apt install -y jq |
| 31 | + - name: Update Library Metadata and Configurations |
| 32 | + run: | |
| 33 | + LATEST_TAG=$(git describe --tags --abbrev=0) |
| 34 | + LIB_V=$(jq -r .version library.json) |
| 35 | + PROPS_V=$(cat library.properties | grep -oP version=\K.*) |
| 36 | + if [ $LIB_V = $LATEST_TAG ] || [ $PROPS_V = $LATEST_TAG ]; then |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | + set -e |
| 40 | + sed -i -E "s/(version=).*/\1${LATEST_TAG}/" library.properties |
| 41 | + echo ✅ Successfully Modified release tag in library.json file... |
| 42 | + jq ".version = \"${LATEST_TAG}\"" library.json > temp.json && mv temp.json library.json |
| 43 | + echo ✅ Successfully Modified release tag in library.properties file... |
| 44 | + - name: Publish to PlatformIO |
| 45 | + env: |
| 46 | + PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_AUTH_TOKEN }} |
| 47 | + run: | |
| 48 | + pio package publish --no-interactive --type library |
| 49 | + echo 👍 Successfully published to PlatformIO |
| 50 | +
|
| 51 | + update-lib-versions: |
| 52 | + runs-on: ubuntu-latest |
| 53 | + name: Update versions in library.json and library.properties |
| 54 | + needs: pio-publish |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v4 |
| 57 | + with: |
| 58 | + fetch-tags: true |
| 59 | + - name: Update library versions |
| 60 | + run: | |
| 61 | + LATEST_TAG=$(git describe --tags --abbrev=0) |
| 62 | + set -e |
| 63 | + sed -i -E "s/(version=).*/\1${LATEST_TAG}/" library.properties |
| 64 | + jq ".version = \"${LATEST_TAG}\"" library.json > temp.json && mv temp.json library.json |
| 65 | + - name: Push to main branch using PAT |
| 66 | + env: |
| 67 | + PAT: ${{ secrets.CI_PAT }} # new fine-grained PAT with contents = rw |
| 68 | + run: | |
| 69 | + git config --global user.name "GitHub Actions" |
| 70 | + git config --global user.email "actions@github.com" |
| 71 | + git remote set-url origin https://x-access-token:${{ env.PAT }}@github.com/${{ github.repository }} |
| 72 | + git stash |
| 73 | + git pull origin main |
| 74 | + git stash pop |
| 75 | + git add library.json library.properties |
| 76 | + git commit -m "Automated update: Update library.json library.properties" |
| 77 | + git push |
0 commit comments