From 43708b4b47e897ed4ce48b5b52d5fc10dfca79ef Mon Sep 17 00:00:00 2001 From: willybilly981 <291233784+willybilly981@users.noreply.github.com> Date: Wed, 19 Aug 2026 21:05:58 +0900 Subject: [PATCH 1/2] add workflow to build hex --- .github/workflows/build-hex.yml | 59 +++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/build-hex.yml diff --git a/.github/workflows/build-hex.yml b/.github/workflows/build-hex.yml new file mode 100644 index 0000000..bb5b9af --- /dev/null +++ b/.github/workflows/build-hex.yml @@ -0,0 +1,59 @@ +name: Build hex + +on: + release: + types: [published] + workflow_dispatch: + inputs: + version: + description: Version label used in the output file name + required: false + default: v2.4 + +permissions: + contents: write + +env: + CH55X_INDEX_URL: https://raw.githubusercontent.com/DeqingSun/ch55xduino/ch55xduino/package_ch55xduino_mcs51_index.json + # Pinned: the sketch already fills 99% of the 14336 byte flash, so a newer core can overflow it + CH55X_CORE_VERSION: 0.0.26 + FQBN: CH55xDuino:mcs51:ch552:clock=24internal,usb_settings=usbcdc,upload_method=usb,bootloader_pin=p36 + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + # arduino-cli requires the sketch directory name to match the .ino file name + path: CH55xSwitchSerialControl + + - uses: arduino/setup-arduino-cli@v2 + + - name: Install ch55xduino core + run: | + arduino-cli core update-index --additional-urls "$CH55X_INDEX_URL" + arduino-cli core install "CH55xDuino:mcs51@$CH55X_CORE_VERSION" --additional-urls "$CH55X_INDEX_URL" + + - name: Compile + run: arduino-cli compile --fqbn "$FQBN" --output-dir build CH55xSwitchSerialControl + + - name: Name the hex after the release tag + id: hex + run: | + version="${{ github.event.release.tag_name || inputs.version }}" + name="CH55xSwitchSerialControl_${version}.hex" + mv build/CH55xSwitchSerialControl.ino.hex "$name" + echo "name=$name" >> "$GITHUB_OUTPUT" + + - uses: actions/upload-artifact@v4 + with: + name: ${{ steps.hex.outputs.name }} + path: ${{ steps.hex.outputs.name }} + + - name: Attach to release + if: github.event_name == 'release' + run: gh release upload "${{ github.event.release.tag_name }}" "${{ steps.hex.outputs.name }}" --clobber + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} From 78a9ffdf4885611a32a29732535b2272aa1a859c Mon Sep 17 00:00:00 2001 From: willybilly981 <291233784+willybilly981@users.noreply.github.com> Date: Wed, 19 Aug 2026 21:28:24 +0900 Subject: [PATCH 2/2] fix --- .github/workflows/build-hex.yml | 57 ++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-hex.yml b/.github/workflows/build-hex.yml index bb5b9af..1da82f0 100644 --- a/.github/workflows/build-hex.yml +++ b/.github/workflows/build-hex.yml @@ -1,17 +1,23 @@ name: Build hex on: + push: + branches: [main] + pull_request: release: types: [published] workflow_dispatch: inputs: version: - description: Version label used in the output file name + description: Version label for the output file name (defaults to the short commit sha) required: false - default: v2.4 permissions: - contents: write + contents: read + +concurrency: + group: build-hex-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} env: CH55X_INDEX_URL: https://raw.githubusercontent.com/DeqingSun/ch55xduino/ch55xduino/package_ch55xduino_mcs51_index.json @@ -22,38 +28,65 @@ env: jobs: build: runs-on: ubuntu-latest + permissions: + # write is needed only by the release upload step; fork PRs get read regardless + contents: write steps: - uses: actions/checkout@v4 with: + path: src + + - name: Prepare sketch directory + id: sketch + run: | # arduino-cli requires the sketch directory name to match the .ino file name - path: CH55xSwitchSerialControl + name=$(basename "$(ls src/*.ino | head -n1)" .ino) + mv src "$name" + echo "name=$name" >> "$GITHUB_OUTPUT" - uses: arduino/setup-arduino-cli@v2 + - uses: actions/cache@v4 + with: + path: ~/.arduino15 + key: arduino-${{ runner.os }}-ch55x-${{ env.CH55X_CORE_VERSION }} + - name: Install ch55xduino core run: | arduino-cli core update-index --additional-urls "$CH55X_INDEX_URL" arduino-cli core install "CH55xDuino:mcs51@$CH55X_CORE_VERSION" --additional-urls "$CH55X_INDEX_URL" - name: Compile - run: arduino-cli compile --fqbn "$FQBN" --output-dir build CH55xSwitchSerialControl + env: + SKETCH: ${{ steps.sketch.outputs.name }} + run: arduino-cli compile --fqbn "$FQBN" --output-dir build "$SKETCH" - name: Name the hex after the release tag id: hex + env: + SKETCH: ${{ steps.sketch.outputs.name }} + RELEASE_TAG: ${{ github.event.release.tag_name }} + INPUT_VERSION: ${{ inputs.version }} run: | - version="${{ github.event.release.tag_name || inputs.version }}" - name="CH55xSwitchSerialControl_${version}.hex" - mv build/CH55xSwitchSerialControl.ino.hex "$name" - echo "name=$name" >> "$GITHUB_OUTPUT" + version="${RELEASE_TAG:-$INPUT_VERSION}" + [ -n "$version" ] || version="${GITHUB_SHA::7}" + # upload-artifact rejects / : < > | * ? \ " in names, and tags may contain them + version="${version//[^A-Za-z0-9._-]/-}" + base="${SKETCH}_${version}" + mv "build/${SKETCH}.ino.hex" "$base.hex" + echo "base=$base" >> "$GITHUB_OUTPUT" - uses: actions/upload-artifact@v4 with: - name: ${{ steps.hex.outputs.name }} - path: ${{ steps.hex.outputs.name }} + # no .hex suffix: the download is zipped either way, and .hex.zip confuses people + name: ${{ steps.hex.outputs.base }} + path: ${{ steps.hex.outputs.base }}.hex - name: Attach to release if: github.event_name == 'release' - run: gh release upload "${{ github.event.release.tag_name }}" "${{ steps.hex.outputs.name }}" --clobber env: GH_TOKEN: ${{ github.token }} GH_REPO: ${{ github.repository }} + RELEASE_TAG: ${{ github.event.release.tag_name }} + HEX: ${{ steps.hex.outputs.base }}.hex + run: gh release upload "$RELEASE_TAG" "$HEX" --clobber