Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic artifact release and flash #1

Open
renxida opened this issue Sep 16, 2023 · 0 comments
Open

Automatic artifact release and flash #1

renxida opened this issue Sep 16, 2023 · 0 comments

Comments

@renxida
Copy link

renxida commented Sep 16, 2023

I have a custom version of this repo that:

  1. Auotmatically releases the artifacts for a consistent download link for the newest version
  2. Includes a script that automatically flashes a NICENANO hands free, without needing to press anything on the keyboard

It would be very nice if we could include these by default with the repo... It took me a while to figure all of this out on my own.

Here's my .github/workflows/build.yml:

on: [push, pull_request, workflow_dispatch]

jobs:
  build:
    uses: zmkfirmware/zmk/.github/workflows/build-user-config.yml@main

  release:
    needs: build
    if: github.event_name == 'push' && github.ref == 'refs/heads/master'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Download firmware artifacts
        uses: actions/download-artifact@v2
        with:
          name: firmware # This should match the archive_name input in your build job

      - name: Calculate new version
        run: |
          git fetch --tags
          DATE=$(date +'%Y%m%d%H%M%S')
          LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null || echo "v0.0.0")
          NEW_TAG="v$(echo $LATEST_TAG | awk -F. -v OFS=. '{$NF = $NF + 1;} 1')-$DATE"
          echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV


      - name: Create git tag
        run: |
          git config user.name github-actions
          git config user.email [email protected]
          git tag ${{ env.NEW_TAG }}
          git push origin ${{ env.NEW_TAG }}

      - name: Create GitHub Release
        uses: marvinpinto/action-automatic-releases@latest
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          automatic_release_tag: "latest"
          prerelease: false
          title: "Release ${{ env.NEW_TAG }}"
          files: |
            /home/runner/work/zmk-config/zmk-config/*

And here's my flashkbd.sh

#!/bin/bash

# Create a unique timestamped folder in /tmp
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
TEMP_DIR="/tmp/firmware_$TIMESTAMP"
mkdir $TEMP_DIR

# Step 1: Download and unzip firmware files to the unique timestamped folder
wget -P $TEMP_DIR https://github.com/renxida/zmk-config/releases/download/latest/lily58_left-nice_nano_v2-zmk.uf2
wget -P $TEMP_DIR https://github.com/renxida/zmk-config/releases/download/latest/lily58_right-nice_nano_v2-zmk.uf2

# Step 2: Ensure NICENANO exists before proceeding with the copy
while [ ! -d "/media/$USER/NICENANO" ]; do
    echo "Please plug in and reset the left half of the keyboard."
    sleep 1
done

# Copy the *left-nice_nano*.uf2 file
cp $TEMP_DIR/*left-nice_nano*.uf2 "/media/$USER/NICENANO/"

# Step 3: Wait for /media/$USER/NICENANO to disappear
while [ -d "/media/$USER/NICENANO" ]; do
    sleep 1
done

# Prompt the user to plug in and reset the right half of the keyboard

# Step 4: Wait for /media/$USER/NICENANO to reappear
while [ ! -d "/media/$USER/NICENANO" ]; do
    echo "Please plug in and reset the right half of the keyboard."
    sleep 1
done

# Step 5: Copy the *right-nice_nano*.uf2 file
cp $TEMP_DIR/*right-nice_nano*.uf2 "/media/$USER/NICENANO/"

# Step 6: Cleanup
rm -rf $TEMP_DIR

echo "Script executed successfully."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant