Skip to content

Deploy PlatformIO library #55

Deploy PlatformIO library

Deploy PlatformIO library #55

name: "Deploy PlatformIO library"
on:
workflow_dispatch:
inputs:
version:
type: string
# Start only after Build was finished
workflow_run:
workflows: [Build]
branches: [main]
types: [completed]
jobs:
check-hsmcpp-version:
# only run for successful build after push event
# avoid running this action on forks
if: ${{ (github.repository == 'igor-krechetov/hsmcpp') && ((github.event.workflow_run == null) || ((github.event.workflow_run.conclusion == 'success') && (github.event.workflow_run.event == 'push'))) }}
runs-on: ubuntu-latest
outputs:
commit_version: ${{ steps.finalize_version.outputs.commit_version }}
commit_action: ${{ steps.get_version.outputs.commit_action }}
steps:
- uses: actions/checkout@v3
- uses: ./.github/workflows/get-commit-version
id: get_version
with:
repo_dir: ${{ env.GITHUB_WORKSPACE }}
commit_sha: ${{ github.event.workflow_run.head_sha }}
- name: Check user input
if: ${{ github.event.inputs.version != '' }}"
id: check_user_input
run: |
echo "TEMP_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
- name: Check commit version
id: check_commit
if: ${{ github.event.inputs.version == '' }}
run: |
echo "TEMP_VERSION=${{ steps.get_version.outputs.commit_version }}" >> $GITHUB_ENV
- name: Final
id: finalize_version
run: |
echo "commit_version=$TEMP_VERSION" >> $GITHUB_OUTPUT
deploy-platformio:
runs-on: ubuntu-latest
needs: check-hsmcpp-version
# only run for successful build after push event
# avoid running this action on forks
if: ${{ (needs.check-hsmcpp-version.outputs.commit_version != '') }}
env:
target_dir: './platformio_deploy/'
steps:
# need to checkout current repo because workflow is not related with push event
- uses: actions/checkout@v3
- uses: ./.github/workflows/install_platformio
# checkout repositories
- uses: actions/checkout@v3
with:
ref: main
path: './main'
- uses: actions/checkout@v3
with:
ref: platformio_library
path: ${{ env.target_dir }}
# prepare gpg for commit signing
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
workdir: ${{ env.target_dir }}
# deploy files
- name: Generate package
run: |
cmake -S ./main -B ./main/build -DHSMBUILD_TARGET=platformio -DHSMBUILD_PLATFORM=arduino
cmake --build ./main/build --target install
- name: Copy package files to target repository
run: cp -Rv ./main/build/deploy/platformio/* "$target_dir"
- name: Publish PlatformIO package
# only publish release versions or when started manually
if: ${{ (needs.check-hsmcpp-version.outputs.commit_action == 'r') || (github.event.inputs.version != '') }}
env:
PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_TOKEN }}
# $PWD is needed due to an issue in "pio pkg publish". It usese os.path.isdir() and sometimes it doesn't not
# recognize relative path as a directory
run: |
pio pkg publish --type library --no-interactive $PWD/main/build/deploy/platformio/
- name: Prepare commit message
run: |
cd ./main
git log -1 --format=%B ${{ github.event.workflow_run.head_sha }} > ../commit.txt
- name: Commit new files
run: |
cd "$target_dir"
git add -A
git commit -S -F ../commit.txt
git push