Repository: KOINSLOT-Inc/kywy
Pull request #28: Release game uf2s
Author: login: Joe-Lannan
Created: 2025-04-27T02:31:18Z | Merged: 2025-04-29T16:09:07Z

Adds UF2 release
Also edited make compile and make upload to use -t=directory so that auto completion for zsh works to find the files.


Diff:
diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml
index 105ccef9..2119a1c6 100644
--- a/.github/workflows/pr.yaml
+++ b/.github/workflows/pr.yaml
@@ -4,76 +4,122 @@
 
 name: Check Pull Request
 on: pull_request
+permissions:
+  pull-requests: write
+  contents: read
 jobs:
   lint:
     runs-on: ubuntu-latest
     steps:
-    - uses: actions/checkout@v4
-    - run: make .clang-format  # get arduino .clang-format file
-    - uses: jidicula/clang-format-action@v4.15.0       # lint c++ code w/ clang-format
-      with:
-        clang-format-version: '14'
-    - uses: arduino/arduino-lint-action@v2             # lint arduino library requirements
-      with:
-        compliance: strict
-        recursive: true
-        library-manager: update
-    - uses: fsfe/reuse-action@v1                       # lint license requirements
+      - uses: actions/checkout@v4
+      - run: make .clang-format # get arduino .clang-format file
+      - uses: jidicula/clang-format-action@v4.15.0 # lint c++ code w/ clang-format
+        with:
+          clang-format-version: "14"
+      - uses: arduino/arduino-lint-action@v2 # lint arduino library requirements
+        with:
+          compliance: strict
+          recursive: true
+          library-manager: update
+      - uses: fsfe/reuse-action@v1 # lint license requirements
 
   compile:
     runs-on: ubuntu-latest
     steps:
-    - uses: actions/checkout@v4
-    - uses: arduino/compile-sketches@v1
-      with:
-        fqbn: "arduino:mbed_rp2040:pico"
-        enable-warnings-report: true
-        enable-deltas-report: true
+      - name: Checkout
+        uses: actions/checkout@v4
+
+      - name: Build all games
+        uses: arduino/compile-sketches@v1
+        with:
+          fqbn: "arduino:mbed_rp2040:pico"
+          sketch-paths: |
+            - examples
+          sketches-report-path: build_artifacts/sketches_report.json
+          verbose: true
+          enable-warnings-report: true
+          enable-deltas-report: true
+
+      - name: Collect UF2 files
+        run: |
+          mkdir -p build_artifacts
+          find ~/.cache/arduino/ -type f -name '*.uf2' -exec cp {} build_artifacts/ \;
+
+      - name: List built artifacts
+        run: |
+          echo "Built files:"
+          ls -lh build_artifacts
+
+      - name: Upload UF2 build artifacts
+        uses: actions/upload-artifact@v4
+        with:
+          name: build_artifacts
+          path: build_artifacts/
+
+      - name: Comment UF2 artifact link on PR
+        uses: actions/github-script@v7
+        with:
+          github-token: ${{ secrets.GITHUB_TOKEN }}
+          script: |
+            const artifactName = "build_artifacts";
+            const runId = context.runId;
+            const repo = context.repo;
+            const artifactsUrl = `https://github.com/${repo.owner}/${repo.repo}/actions/runs/${runId}`;
+            const commit = context.payload.pull_request.head.sha.slice(0, 7); // short SHA
+      
+            const body = `🛠️ Download build artifacts [here](${artifactsUrl}) (artifact **${artifactName}**).\n\nBuilt from commit \`${commit}\`.`;
+      
+            await github.rest.issues.createComment({
+              issue_number: context.issue.number,
+              owner: repo.owner,
+              repo: repo.repo,
+              body: body,
+            });
 
   check-library-version:
     runs-on: ubuntu-latest
     steps:
-    - uses: actions/checkout@v4
-      with:
-        ref: ${{ github.event.pull_request.head.sha }}
+      - uses: actions/checkout@v4
+        with:
+          ref: ${{ github.event.pull_request.head.sha }}
+
+      - name: Check for src/ or examples/ changes
+        id: check_changes
+        run: |
+          git fetch origin ${{ github.base_ref }}
+          if git diff --name-only origin/${{ github.base_ref }} HEAD | grep -qE '^(src|examples)/'; then
+            echo "changed=true" >> $GITHUB_OUTPUT
+          else
+            echo "changed=false" >> $GITHUB_OUTPUT
+          fi
 
-    - name: Check for src/ or examples/ changes
-      id: check_changes
-      run: |
-        git fetch origin ${{ github.base_ref }}
-        if git diff --name-only origin/${{ github.base_ref }} HEAD | grep -qE '^(src|examples)/'; then
-          echo "changed=true" >> $GITHUB_OUTPUT
-        else
-          echo "changed=false" >> $GITHUB_OUTPUT
-        fi
-        
-    - name: check proposed version bump
-      if: steps.check_changes.outputs.changed == 'true'
-      id: tag
-      uses: anothrNick/github-tag-action@1.71.0
-      env:
-        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-        WITH_V: true
-        INITIAL_VERSION: 1.0.0
-        DRY_RUN: true
-        VERBOSE: true
-    - name: assert version in library.properties is bumped
-      if: steps.check_changes.outputs.changed == 'true'
-      run: |
-        if [ \
-          "$(cat library.properties | grep version | sed 's/version=/v/')" \
-          != "${{ steps.tag.outputs.new_tag }}" \
-        ]; then \
-          new_tag="$(echo '${{ steps.tag.outputs.new_tag }}' | sed 's/v//')"
-          echo "bump the version in library.properties to ${new_tag}!"; \
-          exit 1; \
-        fi
+      - name: check proposed version bump
+        if: steps.check_changes.outputs.changed == 'true'
+        id: tag
+        uses: anothrNick/github-tag-action@1.71.0
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          WITH_V: true
+          INITIAL_VERSION: 1.0.0
+          DRY_RUN: true
+          VERBOSE: true
+      - name: assert version in library.properties is bumped
+        if: steps.check_changes.outputs.changed == 'true'
+        run: |
+          if [ \
+            "$(cat library.properties | grep version | sed 's/version=/v/')" \
+            != "${{ steps.tag.outputs.new_tag }}" \
+          ]; then \
+            new_tag="$(echo '${{ steps.tag.outputs.new_tag }}' | sed 's/v//')"
+            echo "bump the version in library.properties to ${new_tag}!"; \
+            exit 1; \
+          fi
 
   build-docs:
     runs-on: ubuntu-latest
     steps:
-    - uses: actions/checkout@v4
-    - uses: actions/setup-python@v5
-    - run: pip install pipenv
-    - run: sudo apt-get install doxygen
-    - run: make docs
+      - uses: actions/checkout@v4
+      - uses: actions/setup-python@v5
+      - run: pip install pipenv
+      - run: sudo apt-get install doxygen
+      - run: make docs
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index fb3fb8fb..b18933c6 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -6,10 +6,11 @@ name: Release
 on:
   push:
     branches:
-    - main
-    paths:  # Only trigger if these files were changed
-    - 'src/**' 
-    - 'examples/**'
+      - main
+    paths:
+      - "src/**"
+      - "examples/**"
+
 jobs:
   version:
     if: github.event.pull_request.merged == true
@@ -17,18 +18,18 @@ jobs:
     permissions:
       contents: write
     steps:
-    - name: check out with tags
-      uses: actions/checkout@v4
-      with:
-        ref: ${{ github.event.pull_request.merge_commit_sha }}
-        fetch-depth: '0'
-    - name: bump version
-      id: tag
-      uses: anothrNick/github-tag-action@1.71.0
-      env:
-        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-        WITH_V: true
-        INITIAL_VERSION: 1.0.0
+      - name: check out with tags
+        uses: actions/checkout@v4
+        with:
+          ref: ${{ github.event.pull_request.merge_commit_sha }}
+          fetch-depth: "0"
+      - name: bump version
+        id: tag
+        uses: anothrNick/github-tag-action@1.71.0
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          WITH_V: true
+          INITIAL_VERSION: 1.0.0
     outputs:
       new_tag: ${{ steps.tag.outputs.new_tag }}
       old_tag: ${{ steps.tag.outputs.old_tag }}
@@ -40,13 +41,27 @@ jobs:
     permissions:
       contents: write
     steps:
-    - name: check out with tags
-      uses: actions/checkout@v4
-      with:
-        fetch-depth: 0
-    - name: create release
-      uses: marvinpinto/action-automatic-releases@v1.2.1
-      with:
-        repo_token: ${{ secrets.GITHUB_TOKEN }}
-        prerelease: false
-        automatic_release_tag: ${{ needs.version.outputs.new_tag }}
+      - name: check out with tags
+        uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+
+      - name: Build all games
+        uses: arduino/compile-sketches@v1
+        with:
+          fqbn: "arduino:mbed_rp2040:pico"
+          sketch-paths: |
+            - examples/games
+
+      - name: Collect UF2 files
+        run: |
+          mkdir -p build_artifacts
+          find ~/.cache/arduino/ -type f -name '*.uf2' -exec cp {} build_artifacts/ \;
+
+      - name: Create Release
+        uses: marvinpinto/action-automatic-releases@v1.2.1
+        with:
+          repo_token: ${{ secrets.GITHUB_TOKEN }}
+          prerelease: false
+          automatic_release_tag: ${{ needs.version.outputs.new_tag }}
+          files: build_artifacts/*.uf2
diff --git a/.gitignore b/.gitignore
index 2fe2858f..24ab292a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,4 +14,6 @@ src/src.ino
 .clang-format
 _site
 __pycache__
-.arduino
\ No newline at end of file
+.arduino
+output
+.secrets
diff --git a/Makefile b/Makefile
index fc0fdb58..787158e2 100644
--- a/Makefile
+++ b/Makefile
@@ -10,8 +10,8 @@ help:
 	@echo "- 'check-licenses': runs 'reuse' to check licenses"
 	@echo "- 'update-licenses': runs 'reuse' to update licenses"
 	@echo "- 'lint': lints all files (code, config, license, etc.)"
-	@echo "- 'upload/examples/<example>': uploads the specified '<example>'"
-	@echo "- 'build/examples/<example>': builds the specified '<example>'"
+	@echo "- 'upload t=examples/<example>': uploads the specified '<example>'"
+	@echo "- 'compile t=examples/<example>': builds the specified '<example>'"
 
 CACHE := .cache
 $(CACHE):
@@ -108,25 +108,33 @@ lint: check-licenses lint-arduino-code lint-python-code
 .PHONY: format
 format: format-arduino-code format-python-code
 
-.PHONY: compile/examples/%
-compile/examples/%: $(ARDUINO_CLI)
-	@port=$$(arduino-cli board list --json \
-		| jq -r '.detected_ports | map(select(.matching_boards)) | .[0].port.address' \
-	) \
-	&& arduino-cli compile \
+.PHONY: compile upload
+compile:
+	@if [ -z "$(t)" ]; then \
+        echo "Error: No Target specified. Use t=<path>"; \
+        exit 1; \
+    fi
+	arduino-cli compile \
 		-b arduino:mbed_rp2040:pico \
-		-p $$port \
-		$$(echo $@ | cut -d'/' -f 2-)
-
-.PHONY: upload/examples/%
-upload/examples/%: $(ARDUINO_CLI) compile/examples/%
+		--library ./ \
+		--build-path './output/$(t)' \
+		$(t)
+
+upload: compile
+	@if [ -z "$(t)" ]; then \
+		echo "Error: No Target specified. Use -t <path> "; \
+		exit 1; \
+	fi
 	@port=$$(arduino-cli board list --json \
 		| jq -r '.detected_ports | map(select(.matching_boards)) | .[0].port.address' \
 	) \
+	&& echo "Found device: $$port"
 	&& arduino-cli upload \
 		-b arduino:mbed_rp2040:pico \
 		-p $$port \
-		$$(echo $@ | cut -d'/' -f 2-)
+		--library ./ \
+		--input-dir './output/$(t)' \
+		$(t)
 
 .PHONY: docs
 docs: $(PYTHON_DEPS) $(DOXYGEN)


Reviews:
user: login: KywyErik
state: CHANGES_REQUESTED
author_association: COLLABORATOR
submitted_at: 2025-04-27T12:22:44Z
user: login: KywyErik
body: I think one leftover bit of code to remove but otherwise looks good
state: CHANGES_REQUESTED
author_association: COLLABORATOR
submitted_at: 2025-04-27T20:19:03Z
user: login: KywyErik
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-04-29T16:05:28Z

Review comments:
diff_hunk: @@ -0,0 +1,43 @@
+# SPDX-FileCopyrightText: 2025 KOINSLOT, Inc.
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+name: Test Release Build
+on:
+  pull_request:
+    branches:
+      - main
+
+jobs:
+  test-release-build:
+    runs-on: ubuntu-22.04
+    permissions:
+      contents: read
+    steps:
+      - name: Check out code
+        uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+
+      - name: Install dependencies
+        run: |
+          sudo apt-get update
+          sudo apt-get install -y make jq
+          curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
+          sudo mv bin/arduino-cli /usr/local/bin/
+          arduino-cli core install arduino:mbed_rp2040
+
+      - name: Build all games
path: .github/workflows/test_release.yaml
user: login: KywyErik
body: Instead of rolling our own we should just use the existing arduino compile sketches action that's already in use in the PR workflow

You can pass cli args to that so you can specify the output directory, and just upload the resulting uf2 files as artifacts so the release job can use them
created_at: 2025-04-27T12:22:39Z
author_association: COLLABORATOR
diff_hunk: @@ -40,13 +41,30 @@ jobs:
     permissions:
       contents: write
     steps:
-    - name: check out with tags
-      uses: actions/checkout@v4
-      with:
-        fetch-depth: 0
-    - name: create release
-      uses: marvinpinto/action-automatic-releases@v1.2.1
-      with:
-        repo_token: ${{ secrets.GITHUB_TOKEN }}
-        prerelease: false
-        automatic_release_tag: ${{ needs.version.outputs.new_tag }}
+      - name: check out with tags
+        uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+
+      - name: Make output dir
+        run: mkdir output
path: .github/workflows/release.yaml
user: login: KywyErik
body: I think this is unused now

```suggestion
```

created_at: 2025-04-27T20:11:39Z
author_association: COLLABORATOR

PR comments:
user: login: Joe-Lannan
created_at: 2025-04-27T19:51:50Z
body: Moved the test release to pr.yaml so it doesn't double compile. Now uses arduino/compile-sketches rather than make
author_association: MEMBER
user: login: github-actions[bot]
created_at: 2025-04-28T23:50:42Z
body: 🛠️ Download build artifacts [here](https://github.com/KOINSLOT-Inc/kywy/actions/runs/14720142187) (look for **uf2-artifacts**).
author_association: NONE
user: login: github-actions[bot]
created_at: 2025-04-28T23:55:17Z
body: 🛠️ Download build artifacts [here](https://github.com/KOINSLOT-Inc/kywy/actions/runs/14720198652) (look for **uf2-artifacts**).
author_association: NONE
user: login: github-actions[bot]
created_at: 2025-04-29T00:02:27Z
body: 🛠️ Download build artifacts [here](https://github.com/KOINSLOT-Inc/kywy/actions/runs/14720268577) (look for **build_artifacts**).
author_association: NONE
user: login: github-actions[bot]
created_at: 2025-04-29T00:15:47Z
body: 🛠️ Download build artifacts [here](https://github.com/KOINSLOT-Inc/kywy/actions/runs/14720443323) (artifact **build_artifacts**).

Built from commit `1f6fdd0`.
author_association: NONE
user: login: Joe-Lannan
created_at: 2025-04-29T00:20:23Z
body: Added file output comments to check builds

author_association: MEMBER
user: login: github-actions[bot]
created_at: 2025-04-29T16:09:01Z
body: 🛠️ Download build artifacts [here](https://github.com/KOINSLOT-Inc/kywy/actions/runs/14735995856) (artifact **build_artifacts**).

Built from commit `adb546d`.
author_association: NONE