From 7e102106bc7e0d5eb7c88c821c38d529f90fb1fc Mon Sep 17 00:00:00 2001 From: urob <978080+urob@users.noreply.github.com> Date: Tue, 10 Dec 2024 10:26:29 -0500 Subject: [PATCH] Move maintainance workflows to own repo --- .github/workflows/release.yml | 13 +++ .github/workflows/run-module-tests.yml | 118 ------------------------- .github/workflows/test.yml | 4 +- .github/workflows/upgrade-zmk.yml | 68 ++------------ 4 files changed, 20 insertions(+), 183 deletions(-) create mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/run-module-tests.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8cdf129 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,13 @@ +name: Create a new module release +on: + pull_request: + types: + - closed + branches: + - main + +jobs: + build: + permissions: + contents: write + uses: urob/zmk-modules-actions/.github/workflows/upgrade-module.yml@main diff --git a/.github/workflows/run-module-tests.yml b/.github/workflows/run-module-tests.yml deleted file mode 100644 index f9423b8..0000000 --- a/.github/workflows/run-module-tests.yml +++ /dev/null @@ -1,118 +0,0 @@ -name: Reusable module tests - -on: - workflow_call: - inputs: - tests_path: - description: "Path to the tests directory" - default: "tests" - required: false - type: string - -jobs: - collect-tests: - outputs: - test_cases: ${{ env.test_cases }} - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Find test directories - working-directory: ${{ inputs.tests_path }} - run: | - test_cases=$(find * -name native_posix_64.keymap -exec dirname \{\} \; | sed "s#^\./##" | jq -R -s -c 'split("\n")[:-1]') - echo "test_cases=${test_cases}" >> $GITHUB_ENV - jq <<< ${test_cases} - - run-tests: - runs-on: ubuntu-latest - container: - image: docker.io/zmkfirmware/zmk-build-arm:3.5 - needs: collect-tests - strategy: - matrix: - test: ${{ fromJSON(needs.collect-tests.outputs.test_cases) }} - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Create build directory - run: | - echo "build_dir=$(mktemp -d)" >> $GITHUB_ENV - - - name: Copy test files to isolated temporary directory - run: | - base_dir="${TMPDIR:-/tmp}/zmk-module-tests" - mkdir -p "${base_dir}/${{ inputs.tests_path }}" - cp -R ${{ inputs.tests_path }}/* "${base_dir}/${{ inputs.tests_path }}/" - echo "base_dir=${base_dir}" >> $GITHUB_ENV - - - name: Cache west modules - uses: actions/cache@v4 - continue-on-error: true - env: - cache-name: cache-zephyr-modules - with: - path: | - ${{ env.base_dir }}/modules/ - ${{ env.base_dir }}/tools/ - ${{ env.base_dir }}/zephyr/ - ${{ env.base_dir }}/bootloader/ - ${{ env.base_dir }}/zmk/ - key: - ${{ runner.os }}-build-${{ env.cache-name }}-${{ - hashFiles('**/west.yml') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: Initialize workspace (west init) - working-directory: ${{ env.base_dir }} - run: west init -l "${{ env.base_dir }}/${{ inputs.tests_path }}" - - - name: Update modules (west update) - working-directory: ${{ env.base_dir }} - run: west update - - - name: Export Zephyr CMake package (west zephyr-export) - working-directory: ${{ env.base_dir }} - run: west zephyr-export - - - name: West Build (${{ matrix.test }}) - working-directory: ${{ env.base_dir }} - env: - config_dir: ${{ env.base_dir }}/${{ inputs.tests_path }}/${{ matrix.test }} - run: - west build -s zmk/app -d "${{ env.build_dir }}" -b native_posix_64 -- \ - -DCONFIG_ASSERT=y -DZMK_CONFIG="${config_dir}" -DZMK_EXTRA_MODULES="${GITHUB_WORKSPACE}" - - - name: Test - working-directory: ${{ env.base_dir }} - env: - in: ${{ inputs.tests_path }}/${{ matrix.test }} - out: ${{ env.build_dir }} - run: | - ${out}/zephyr/zmk.exe | sed -e "s/.*> //" | - tee ${out}/keycode_events_full.log | - sed -n -f ${in}/events.patterns > ${out}/keycode_events.log - diff -auZ ${in}/keycode_events.snapshot ${out}/keycode_events.log - if [ $? -gt 0 ]; then - if [ -f ${in}/pending ]; then - echo "PENDING: ${{ matrix.test }}" | tee -a ${out}/pass-fail.log - exit 0 - fi - - echo "FAILED: ${{ matrix.test }}" | tee -a ${out}/pass-fail.log - exit 1 - fi - echo "PASS: ${{ matrix.test }}" | tee -a ${out}/pass-fail.log - exit 0 - - - name: Archive artifacts - if: ${{ always() }} - uses: actions/upload-artifact@v4 - with: - name: "log-files" - path: ${{ env.build_dir }}/**/*.log diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f316562..6cc86ac 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Tests +name: Run tests on: workflow_dispatch: @@ -17,4 +17,4 @@ on: jobs: build: - uses: urob/zmk-leader-key/.github/workflows/run-module-tests.yml@main + uses: urob/zmk-modules-actions/.github/workflows/run-tests.yml@main diff --git a/.github/workflows/upgrade-zmk.yml b/.github/workflows/upgrade-zmk.yml index 981d6d4..554b58e 100644 --- a/.github/workflows/upgrade-zmk.yml +++ b/.github/workflows/upgrade-zmk.yml @@ -1,71 +1,13 @@ -name: Upgrade to latest ZMK version +name: Check for new ZMK releases on: workflow_dispatch: schedule: - # Runs every day at 22:00 UTC (17:00 ET) - - cron: "0 22 * * *" - -env: - upstream: zmkfirmware/zmk - west_path: tests/west.yml - upgrade_branch: upgrade-zmk - upgrade-label: "upgrade-version" + - cron: "0 22 * * *" # Run daily at 22:00 UTC (17:00 ET) jobs: - upgrade-zmk: - name: Upgrade ZMK & open PR - runs-on: ubuntu-latest + build: + uses: urob/zmk-modules-actions/.github/workflows/upgrade-zmk.yml@main permissions: contents: write - pull-requests: write - actions: write - steps: - - name: Checkout main branch - uses: actions/checkout@v4 - - - name: Get latest ZMK version - id: get-zmk-version - run: | - ZMK_VERSION=$(curl -s https://api.github.com/repos/${{ env.upstream }}/releases/latest | jq -r '.tag_name') - echo "ZMK_VERSION=${ZMK_VERSION%.*}" >> $GITHUB_ENV - echo "ZMK_VERSION: ${ZMK_VERSION%.*}" - - - name: Upgrade ZMK version - run: | - export ver=${{ env.ZMK_VERSION }} - yq e -i '(.manifest.projects[] | select(.name=="zmk") | .revision) = env(ver)' ${{ env.west_path }} - cat ${{ env.west_path }} - - - name: Detect changes - id: changes - run: - # This output boolean tells us if the dependencies have actually changed - echo "count=$(git status --porcelain=v1 2>/dev/null | wc -l)" >> $GITHUB_OUTPUT - - - name: Commit & push changes - # Only push if changes exist - if: steps.changes.outputs.count > 0 - run: | - git config user.name github-actions - git config user.email github-actions@github.com - git commit -a -m "Upgrade ZMK to ${{ env.ZMK_VERSION }}" - git push -f origin ${{ github.ref_name }}:${{ env.upgrade_branch }} - - - name: Open pull request if needed - if: steps.changes.outputs.count > 0 - run: | - # Personal access token requires: Repo read access to metadata, read & write acess to actions and pull requests - # https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow - echo "${{ secrets.ACTIONS_UPGRADE_ZMK }}" | gh auth login --with-token - # Only open a PR if the branch is not attached to an existing one - PR=$(gh pr list --head ${{ env.upgrade_branch }} --json number -q '.[0].number') - if [ -z $PR ]; then - gh pr create \ - --head ${{ env.upgrade_branch }} \ - --title "Upgrade ZMK to ${{ env.ZMK_VERSION }}" \ - --label "${{ env.upgrade-label }}" \ - --body "Full log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" - else - echo "Pull request already exists, won't create a new one." - fi + secrets: inherit