diff --git a/.github/workflows/firmware_build.yml b/.github/workflows/firmware_build.yml deleted file mode 100644 index 87c10f0..0000000 --- a/.github/workflows/firmware_build.yml +++ /dev/null @@ -1,205 +0,0 @@ -name: "Combined Firmware Workflow" - -on: - workflow_dispatch: - push: - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - - build: - runs-on: ubuntu-latest - steps: - - name: Checkout repo - uses: actions/checkout@v2 - with: - submodules: 'recursive' - - - name: Build Docker image containing toolchains - run: docker build -t my-image . - - - name: Run script in Docker container - run: docker run -v $PWD:/project -w /project/ my-image sh -c "cd Firmware && idf.py build" - - - name: Run Unit Tests - run: | - cd Firmware/components/knot_midi_translator/host_test/ - ./test.sh - ./test.sh >> test.txt - - - name: Convert to uf2 - run: | - cd Firmware - sudo python3 ./tools/uf2conv.py -f ESP32S3 ./build/midi_host_fw.bin -b 0x0 -c -o ./output/midi_host_fw.uf2 - - - name: Set env - shell: bash - run: | - echo "ACTION_DATE=$(date +'%Y-%m-%d-%H%M')" >> $GITHUB_ENV - echo "RELEASE_VERSION=$(git tag --contains ${{ github.sha }})" >> $GITHUB_ENV - - - name: Copy and rename the artifacts - run: | - ls - cp Firmware/output/midi_host_fw.uf2 knot_esp32_release_${{ env.ACTION_DATE }}.uf2 - cp Firmware/output/midi_host_fw.uf2 knot_esp32_nightly_${{ env.ACTION_DATE }}.uf2 - cp Firmware/output/midi_host_fw.uf2 knot_esp32_nightly.uf2 - - - uses: actions/upload-artifact@v4 - with: - name: nightly_firmware - path: | - knot_esp32_nightly_${{ env.ACTION_DATE }}.uf2 - knot_esp32_nightly.uf2 - - - name: Zipping artifacts for Github Release - uses: vimtor/action-zip@v1 - if: ${{ env.RELEASE_VERSION != '' }} - with: - files: knot_esp32_release_${{ env.ACTION_DATE }}.uf2 - dest: knot_release.zip - - - name: Release - uses: softprops/action-gh-release@v1 - if: ${{ env.RELEASE_VERSION != '' }} - with: - tag_name: ${{ env.RELEASE_VERSION }} - name: Knot ${{ env.RELEASE_VERSION }} (${{ env.ACTION_DATE }}) - files: knot_release.zip - draft: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - publish-nightly-release: - runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' - needs: build - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - fetch-tags: true - fetch-depth: 0 - - - name: Generate tag name - id: get_version - run: | - tag_name="nightly" - echo "Tag name: $tag_name" - echo "tag_name=$tag_name" >> $GITHUB_OUTPUT - - - name: Delete all releases by name - id: delete_releases_by_name - run: | - release_name="Nightly build" # Replace with the release name you want to delete - echo "Deleting all releases with the name: $release_name" - - # Fetch all releases - releases=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/releases") - - # Find and delete all releases matching the given name - echo "$releases" | jq -c --arg release_name "$release_name" '.[] | select(.name == $release_name) | .id' | while read release_id; do - echo "Deleting release with ID: $release_id" - - # Delete the release by ID - curl -s -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/releases/$release_id" - - echo "Deleted release with ID: $release_id" - done - - - name: Remove Nightly Tags - run: | - # Configure Git - echo "Configuring Git..." - git config --global user.name "github-actions[bot]" - git config --global user.email "github-actions[bot]@users.noreply.github.com" - - # Get all tags containing "nightly" - echo "Retrieving all tags containing 'nightly'..." - nightly_tags=$(git tag -l "*nightly") - echo "Nightly tags found: $nightly_tags" - - # Loop through each nightly tag and delete it locally and remotely - if [ -z "$nightly_tags" ]; then - echo "No nightly tags found. Exiting..." - else - for tag in $nightly_tags; do - echo "Deleting tag: $tag" - git tag -d "$tag" # Delete tag locally - git push origin ":refs/tags/$tag" - done - fi - echo "Tag deletion process completed." - - - name: Download all nightly artifacts - uses: actions/download-artifact@v4 - with: - path: build/ # Path to save the downloaded artifacts - merge-multiple: true - - - name: Remove duplicate file (the one that does not have date in the name) - run: | - rm build/*nightly.uf2 - - - name: Build Changelog - id: github_release - uses: mikepenz/release-changelog-builder-action@v5 - with: - toTag: ${{ github.ref }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Release Nightly - uses: softprops/action-gh-release@v1 - with: - name: Release Nightly Version - tag_name: ${{ steps.get_version.outputs.tag_name }} - files: build/*.* - draft: false - prerelease: true - body: ${{steps.github_release.outputs.changelog}} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - deploy-results: - runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' - needs: build - steps: - - uses: actions/checkout@v2 - with: - ref: preview - - - name: Download reports' artifacts - uses: actions/download-artifact@v4 - with: - path: download - - - name: Collecting files - run: | - - # Create the temp folder if it doesn't exist - mkdir -p Preview/Firmware - - # Loop through each subdirectory in the download folder - for subdirectory in download/*; do - # Check if it is a directory - if [ -d "$subdirectory" ]; then - # Copy the contents of the subdirectory to the temp folder - cp -r "$subdirectory"/* "Preview/Firmware/" - fi - done - - - name: Commit the files - run: | - git config --global user.name ${{ github.actor }} - git config --global user.email ${{ github.actor }}@users.noreply.github.com - git add Preview/* - git commit -m "BOT ${{ github.workflow }} ${{ github.sha }}" - git push diff --git a/.github/workflows/firmware_build_only.yml b/.github/workflows/firmware_build_only.yml new file mode 100644 index 0000000..8935069 --- /dev/null +++ b/.github/workflows/firmware_build_only.yml @@ -0,0 +1,89 @@ +name: "Firmware Build and Test" + +on: + workflow_call: + outputs: + artifact_name: + description: "Name of the uploaded artifact" + value: ${{ jobs.build.outputs.artifact_name }} + action_date: + description: "Build date timestamp" + value: ${{ jobs.build.outputs.action_date }} + release_version: + description: "Git tag version if exists" + value: ${{ jobs.build.outputs.release_version }} + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + outputs: + artifact_name: nightly_firmware + action_date: ${{ steps.set_env.outputs.action_date }} + release_version: ${{ steps.set_env.outputs.release_version }} + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + submodules: 'recursive' + + - name: Build Docker image containing toolchains + run: docker build -t my-image . + + - name: Run script in Docker container + run: docker run -v $PWD:/project -w /project/ my-image sh -c "cd Firmware && idf.py build" + + - name: Run Unit Tests + run: | + cd Firmware/components/knot_midi_translator/host_test/ + ./test.sh + ./test.sh >> test.txt + + - name: Convert to uf2 + run: | + cd Firmware + sudo python3 ./tools/uf2conv.py -f ESP32S3 ./build/midi_host_fw.bin -b 0x0 -c -o ./output/midi_host_fw.uf2 + + - name: Set env + id: set_env + shell: bash + run: | + ACTION_DATE=$(date +'%Y-%m-%d-%H%M') + RELEASE_VERSION=$(git tag --contains ${{ github.sha }}) + echo "ACTION_DATE=$ACTION_DATE" >> $GITHUB_ENV + echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV + echo "action_date=$ACTION_DATE" >> $GITHUB_OUTPUT + echo "release_version=$RELEASE_VERSION" >> $GITHUB_OUTPUT + + - name: Copy and rename the artifacts + run: | + ls + cp Firmware/output/midi_host_fw.uf2 knot_esp32_release_${{ env.ACTION_DATE }}.uf2 + cp Firmware/output/midi_host_fw.uf2 knot_esp32_nightly_${{ env.ACTION_DATE }}.uf2 + cp Firmware/output/midi_host_fw.uf2 knot_esp32_nightly.uf2 + + - name: Upload nightly artifacts + uses: actions/upload-artifact@v4 + with: + name: nightly_firmware + path: | + knot_esp32_nightly_${{ env.ACTION_DATE }}.uf2 + knot_esp32_nightly.uf2 + + - name: Zipping artifacts for Github Release + uses: vimtor/action-zip@v1 + if: ${{ env.RELEASE_VERSION != '' }} + with: + files: knot_esp32_release_${{ env.ACTION_DATE }}.uf2 + dest: knot_release.zip + + - name: Release + uses: softprops/action-gh-release@v1 + if: ${{ env.RELEASE_VERSION != '' }} + with: + tag_name: ${{ env.RELEASE_VERSION }} + name: Knot ${{ env.RELEASE_VERSION }} (${{ env.ACTION_DATE }}) + files: knot_release.zip + draft: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/firmware_deploy_preview.yml b/.github/workflows/firmware_deploy_preview.yml new file mode 100644 index 0000000..2055fec --- /dev/null +++ b/.github/workflows/firmware_deploy_preview.yml @@ -0,0 +1,42 @@ +name: "Firmware Deploy to Preview" + +on: + workflow_call: + workflow_dispatch: + +jobs: + deploy-results: + runs-on: ubuntu-latest + steps: + - name: Checkout preview branch + uses: actions/checkout@v2 + with: + ref: preview + + - name: Download reports' artifacts + uses: actions/download-artifact@v4 + with: + path: download + + - name: Collecting files + run: | + + # Create the temp folder if it doesn't exist + mkdir -p Preview/Firmware + + # Loop through each subdirectory in the download folder + for subdirectory in download/*; do + # Check if it is a directory + if [ -d "$subdirectory" ]; then + # Copy the contents of the subdirectory to the temp folder + cp -r "$subdirectory"/* "Preview/Firmware/" + fi + done + + - name: Commit the files + run: | + git config --global user.name ${{ github.actor }} + git config --global user.email ${{ github.actor }}@users.noreply.github.com + git add Preview/* + git commit -m "BOT ${{ github.workflow }} ${{ github.sha }}" + git push diff --git a/.github/workflows/firmware_release_nightly.yml b/.github/workflows/firmware_release_nightly.yml new file mode 100644 index 0000000..f6630a9 --- /dev/null +++ b/.github/workflows/firmware_release_nightly.yml @@ -0,0 +1,103 @@ +name: "Firmware Nightly Release" + +on: + workflow_call: + workflow_dispatch: + +jobs: + publish-nightly-release: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-tags: true + fetch-depth: 0 + + - name: Generate tag name + id: get_version + run: | + tag_name="nightly" + echo "Tag name: $tag_name" + echo "tag_name=$tag_name" >> $GITHUB_OUTPUT + + - name: Delete all releases by name + id: delete_releases_by_name + run: | + release_name="Nightly Build" # Replace with the release name you want to delete + echo "Deleting all releases with the name: $release_name" + + # Fetch all releases + releases=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/releases") + + # Find and delete all releases matching the given name + echo "$releases" | jq -c --arg release_name "$release_name" '.[] | select(.name == $release_name) | .id' | while read release_id; do + echo "Deleting release with ID: $release_id" + + # Delete the release by ID + curl -s -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/releases/$release_id" + + echo "Deleted release with ID: $release_id" + done + + - name: Remove Nightly Tags + run: | + # Configure Git + echo "Configuring Git..." + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + + # Get all tags containing "nightly" + echo "Retrieving all tags containing 'nightly'..." + nightly_tags=$(git tag -l "*nightly") + echo "Nightly tags found: $nightly_tags" + + # Loop through each nightly tag and delete it locally and remotely + if [ -z "$nightly_tags" ]; then + echo "No nightly tags found. Exiting..." + else + for tag in $nightly_tags; do + echo "Deleting tag: $tag" + git tag -d "$tag" # Delete tag locally + git push origin ":refs/tags/$tag" + done + fi + echo "Tag deletion process completed." + + - name: Download all nightly artifacts + uses: actions/download-artifact@v4 + with: + path: build/ # Path to save the downloaded artifacts + merge-multiple: true + + - name: Remove duplicate file (the one that does not have date in the name) + run: | + rm build/*nightly.uf2 + + - name: Zip nightly artifacts + uses: vimtor/action-zip@v1 + with: + files: build/ + dest: knot_nightly.zip + + - name: Build Changelog + id: github_release + uses: mikepenz/release-changelog-builder-action@v5 + with: + toTag: ${{ github.ref }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Release Nightly + uses: softprops/action-gh-release@v1 + with: + name: Nightly Build + tag_name: ${{ steps.get_version.outputs.tag_name }} + files: knot_nightly.zip + draft: false + prerelease: true + body: ${{steps.github_release.outputs.changelog}} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/firmware_workflow.yml b/.github/workflows/firmware_workflow.yml new file mode 100644 index 0000000..8348bd6 --- /dev/null +++ b/.github/workflows/firmware_workflow.yml @@ -0,0 +1,27 @@ +name: "Firmware Workflow" + +on: + workflow_dispatch: + push: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + build: + name: Build Firmware + uses: ./.github/workflows/firmware_build_only.yml + + publish-nightly: + name: Publish Nightly Release + if: github.ref == 'refs/heads/main' + needs: build + uses: ./.github/workflows/firmware_release_nightly.yml + secrets: inherit + + deploy-preview: + name: Deploy to Preview Branch + if: github.ref == 'refs/heads/main' + needs: build + uses: ./.github/workflows/firmware_deploy_preview.yml