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

Get help action to add to ZMK archive. #58

Open
Eh2406 opened this issue Nov 14, 2023 · 6 comments
Open

Get help action to add to ZMK archive. #58

Eh2406 opened this issue Nov 14, 2023 · 6 comments

Comments

@Eh2406
Copy link

Eh2406 commented Nov 14, 2023

When using ZMK the workflow is that when you push it commit a github action starts that builds a zip download of the firmware. I would really love the key map image to be part of that zip archive. That way if I have multiple archives on my computer I easily tell what key map each set of firmware will use.

I don't know if this is possible, but it would be really cool if it was!

@caksoylar
Copy link
Owner

Hi, this is certainly achievable, but I am pretty sure it would require editing .github/workflows/build.yml in your config repo since that's the only way to write to the same output artifact that I know of.

Copying from the reusable workflow, you could probably append an extra step to the end so that it looks like this:

on: [push, pull_request, workflow_dispatch]

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

  draw:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 1
          submodules: recursive

      - name: Install keymap-drawer (pypi)
        run: python3 -m pip install keymap-drawer

      - name: Draw keymaps
        run: |
          get_args() {
              local keyboard=$2
              eval set -- "$1"
              for arg; do
                  local key=${arg%%:*}
                  local val=${arg#*:}
                  if [ "$key" = "$keyboard" ]; then
                      echo "$val"
                      break
                  fi
              done
          }

          mkdir -p "${{ inputs.output_folder }}"

          config_path="${{ inputs.config_path }}"
          [ -e "$config_path" ] && config_arg=(-c "$config_path") || config_arg=()
          for keymap_file in ${{ inputs.keymap_patterns }}; do
              keyboard=$(basename -s .keymap "$keymap_file")
              echo "INFO: drawing for $keyboard"

              parse_args=$(get_args "${{ inputs.parse_args }}" "$keyboard")
              echo "INFO:   got extra parse args: $parse_args"
              draw_args=$(get_args "${{ inputs.draw_args }}" "$keyboard")
              echo "INFO:   got extra draw args: $draw_args"

              if [ -f "config/${keyboard}.json" ]; then
                  echo "INFO:   found config/${keyboard}.json";
                  draw_args+=" -j config/${keyboard}.json"
              fi

              keymap "${config_arg[@]}" parse -z "$keymap_file" $parse_args >"${{ inputs.output_folder }}/$keyboard.yaml" \
              && keymap "${config_arg[@]}" draw "${{ inputs.output_folder }}/$keyboard.yaml" $draw_args >"${{ inputs.output_folder }}/$keyboard.svg" \
              || echo "ERROR: parsing or drawing failed for $keyboard!"
          done

    - name: Upload drawings
      uses: actions/upload-artifact@v2
      with:
        name: ${{ inputs.archive_name }}
        path: ${{ inputs.output_folder }}/*

You will have to replace all ${{ inputs.* }} values except for ${{ inputs.archive_name }} above (which comes from the ZMK workflow) with your own parameter values.

Here we just called an upload-artifact step rather than a commit step in the workflow. Hopefully with the same filename as ZMK (${{ inputs.archive_name }} -> firmware) it will add on the files to the same output zip.

@Eh2406
Copy link
Author

Eh2406 commented Nov 15, 2023

Thank you so much for the quick and thoughtful response. I tried it and it works perfectly! How hard would it be to add this to the reusable workflow? Could this be another option documented in the readme?

If it would be difficult, or its not something you're interested in merging, feel free to close. And thank you.

@caksoylar
Copy link
Owner

I think it makes sense to add an alternative reusable workflow which integrates build with draw like above, but properly parametrized with the combination of parameters from both steps. I'll take a stab at that soon and close this issue if it happens.

@michaelrommel
Copy link
Contributor

Hm, I believe that you cannot add files to an already existing artifact. You probably would have to pull and extract the ZMK artifact "firmware" then pull/extract the keymap-drawer artifact (see today's PR) merge them and then upload them overwriting the ZMK's firmware artifact. It would get a new id, but keep the name then. And you would need to chain both jobs together with 'need'. That's what my tinktering with this stuff in the last 2 days got me understanding...

@Eh2406
Copy link
Author

Eh2406 commented Feb 15, 2024

Hm, I believe that you cannot add files to an already existing artifact.

I think this may have been a Github change recently. The code caksoylar was working for my, but now gives warnings about updating actions/upload-artifact@v2 to v3

@caksoylar
Copy link
Owner

Sadly the new v3 version doesn't support adding files to existing artifacts. However there is a new merge action that can combine multiple artifacts; we switched to it for ZMK builds: zmkfirmware/zmk#2141

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

3 participants