From 2cadda4e00cac19c90502b944deccc17466f282d Mon Sep 17 00:00:00 2001 From: Scai <59282365+alexevladgabriel@users.noreply.github.com> Date: Tue, 7 Jan 2025 22:40:03 +0000 Subject: [PATCH 01/10] chore: create release workflow --- .github/workflows/release.yaml | 95 ++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..2d25ba2 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,95 @@ +name: Release + +on: + push: + tags: + - "v*" + +jobs: + release: + name: Release + runs-on: ubuntu-22.04 + permissions: + contents: read + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 21 + + - name: Install Dependencies + working-directory: ui + run: npm ci + + - name: Build UI + working-directory: ui + run: npm run build:device + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: Build Release Binaries + env: + REF: ${{ github.ref }} + run: | + GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="-s -w -X kvm.builtAppVersion=${REF:11}" -o bin/jetkvm_app cmd/main.go + chmod 755 bin/jetkvm_app + + - name: Create checksum + env: + REF: ${{ github.ref }} + run: | + SUM=$(shasum -a 256 bin/jetkvm_app | cut -d ' ' -f 1) + echo -e "\n#### SHA256 Checksum\n\`\`\`\n$SUM bin/jetkvm_app\n\`\`\`\n" >> ./RELEASE_CHANGELOG + echo -e "$SUM bin/jetkvm_app\n" > checksums.txt + + - name: Create Release Branch + env: + REF: ${{ github.ref }} + run: | + BRANCH=release/${REF:10} + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git checkout -b ${BRANCH} + git push -u origin ${BRANCH} + sed -i "s/var builtAppVersion = \".*\"/var builtAppVersion = \"${REF:11}\"/" ota.go + git add ota.go + git commit -m "bump version for release" + git push + + - name: Create Release + id: create_release + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + draft: true + prerelease: ${{ contains(github.ref, 'rc') || contains(github.ref, 'beta') || contains(github.ref, 'alpha') }} + body_path: ./RELEASE_CHANGELOG + + - name: Upload JetKVM binary + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: bin/jetkvm_app + asset_name: jetkvm_app + asset_content_type: application/octet-stream + + - name: Upload checksum + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./checksums.txt + asset_name: checksums.txt + asset_content_type: text/plain From 2f7042df180da65ebc680bbc228a7c6efa62c0da Mon Sep 17 00:00:00 2001 From: Scai <59282365+alexevladgabriel@users.noreply.github.com> Date: Tue, 7 Jan 2025 22:58:23 +0000 Subject: [PATCH 02/10] chore: increase permissions to content workflow --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2d25ba2..c9ea4cd 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -10,7 +10,7 @@ jobs: name: Release runs-on: ubuntu-22.04 permissions: - contents: read + contents: write packages: write steps: From 97958e7b86b2adec8868445adec7e8aff4f71f45 Mon Sep 17 00:00:00 2001 From: Scai <59282365+alexevladgabriel@users.noreply.github.com> Date: Wed, 8 Jan 2025 00:13:52 +0000 Subject: [PATCH 03/10] chore: push workflow --- .github/workflows/push.yaml | 99 +++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 .github/workflows/push.yaml diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml new file mode 100644 index 0000000..eac7be6 --- /dev/null +++ b/.github/workflows/push.yaml @@ -0,0 +1,99 @@ +name: Push + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + name: Build + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-22.04] + go: [1.21] + node: [21] + goos: [linux] + goarch: [arm] + permissions: + contents: read + pull-requests: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + + - name: Install Dependencies + working-directory: ui + run: npm ci + + - name: Build UI + working-directory: ui + run: npm run build:device + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + + - name: Install Go Dependencies + run: | + go mod download + + - name: Build Binaries + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + run: | + GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="-s -w -X kvm.builtAppVersion=dev-${GIT_COMMIT:0:7}" -o bin/jetkvm_app cmd/main.go + chmod 755 bin/jetkvm_app + + - name: Upload Debug Artifact + uses: actions/attest-build-provenance@v2 + if: ${{ (github.ref == 'refs/heads/main' || github.event_name == 'pull_request') && matrix.go == '1.21' }} + with: + name: jetkvm_app_debug + path: bin/jetkvm_app + + comment: + runs-on: ubuntu-latest + needs: build + permissions: + contents: read + pull-requests: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Generate Links + id: linksa + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + ARTIFACT_ID=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts --jq '.artifacts[0].id') + echo "ARTIFACT_URL=https://github.com/${{ github.repository }}/actions/artifacts/$ARTIFACT_ID/zip" >> $GITHUB_ENV + echo "LATEST_COMMIT=${GIT_COMMIT:0:7}" >> $GITHUB_ENV + + - name: Comment on PR + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Markdown Table for Comment + COMMENT="✅ **Build succesfully for ${{ github.event.pull_request.title }}!**\n\n" + COMMENT+="| Name | Link |\n" + COMMENT+="|------|------|\n" + COMMENT+="| 🔗 Debug Binary | [Download](${{ env.ARTIFACT_URL }}) |\n" + COMMENT+="| 🔗 Latest commit | [${{ env.LATEST_COMMIT }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) |\n" + + # Post Comment + gh pr comment ${{ github.event.pull_request.number }} --body "$COMMENT" From fab575dbe0c2e08b6e502170b6c1ccd5b3670763 Mon Sep 17 00:00:00 2001 From: Scai <59282365+alexevladgabriel@users.noreply.github.com> Date: Wed, 8 Jan 2025 00:17:38 +0000 Subject: [PATCH 04/10] chore: permissions update on push --- .github/workflows/push.yaml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index eac7be6..c935b76 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -8,6 +8,11 @@ on: branches: - main +permissions: + id-token: write + contents: read + pull-requests: write + jobs: build: name: Build @@ -20,9 +25,6 @@ jobs: node: [21] goos: [linux] goarch: [arm] - permissions: - contents: read - pull-requests: write steps: - name: Checkout @@ -68,9 +70,6 @@ jobs: comment: runs-on: ubuntu-latest needs: build - permissions: - contents: read - pull-requests: write steps: - name: Checkout uses: actions/checkout@v4 From 564eee9b00e526bfd8d0d599522deab245a1bf37 Mon Sep 17 00:00:00 2001 From: Scai <59282365+alexevladgabriel@users.noreply.github.com> Date: Wed, 8 Jan 2025 00:19:52 +0000 Subject: [PATCH 05/10] chore: change to artifact --- .github/workflows/push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index c935b76..f1faf9c 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -61,7 +61,7 @@ jobs: chmod 755 bin/jetkvm_app - name: Upload Debug Artifact - uses: actions/attest-build-provenance@v2 + uses: actions/upload-artifact@v4 if: ${{ (github.ref == 'refs/heads/main' || github.event_name == 'pull_request') && matrix.go == '1.21' }} with: name: jetkvm_app_debug From 1505c37e4c8646661011a82b60269bbba7acca3d Mon Sep 17 00:00:00 2001 From: Scai <59282365+alexevladgabriel@users.noreply.github.com> Date: Wed, 8 Jan 2025 00:29:04 +0000 Subject: [PATCH 06/10] chore: comment fix issues --- .github/workflows/push.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index f1faf9c..0966ddc 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -68,6 +68,7 @@ jobs: path: bin/jetkvm_app comment: + name: Comment runs-on: ubuntu-latest needs: build steps: @@ -80,19 +81,19 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | ARTIFACT_ID=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts --jq '.artifacts[0].id') - echo "ARTIFACT_URL=https://github.com/${{ github.repository }}/actions/artifacts/$ARTIFACT_ID/zip" >> $GITHUB_ENV - echo "LATEST_COMMIT=${GIT_COMMIT:0:7}" >> $GITHUB_ENV + echo "ARTIFACT_URL=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/$ARTIFACT_ID" >> $GITHUB_ENV + echo "LATEST_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - name: Comment on PR env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # Markdown Table for Comment - COMMENT="✅ **Build succesfully for ${{ github.event.pull_request.title }}!**\n\n" + COMMENT="✅ **Build successfully for ${{ github.event.pull_request.title }}!**\n\n" COMMENT+="| Name | Link |\n" COMMENT+="|------|------|\n" COMMENT+="| 🔗 Debug Binary | [Download](${{ env.ARTIFACT_URL }}) |\n" - COMMENT+="| 🔗 Latest commit | [${{ env.LATEST_COMMIT }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) |\n" + COMMENT+="| 🔗 Latest commit | [${{ env.LATEST_COMMIT }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) |" # Post Comment gh pr comment ${{ github.event.pull_request.number }} --body "$COMMENT" From 566305549fdf8ad524e3abf79371be00b8d991fc Mon Sep 17 00:00:00 2001 From: Scai <59282365+alexevladgabriel@users.noreply.github.com> Date: Wed, 8 Jan 2025 00:34:49 +0000 Subject: [PATCH 07/10] chore: fix table comment --- .github/workflows/push.yaml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index 0966ddc..330bdac 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -88,12 +88,21 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - # Markdown Table for Comment - COMMENT="✅ **Build successfully for ${{ github.event.pull_request.title }}!**\n\n" - COMMENT+="| Name | Link |\n" - COMMENT+="|------|------|\n" - COMMENT+="| 🔗 Debug Binary | [Download](${{ env.ARTIFACT_URL }}) |\n" - COMMENT+="| 🔗 Latest commit | [${{ env.LATEST_COMMIT }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) |" + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + TITLE="${{ github.event.pull_request.title }}" + else + TITLE="main branch" + fi + + COMMENT=$(cat << EOF + ✅ **Build successfully for $TITLE!** + + | Name | Link | + |------------------|----------------------------------------------------------------------| + | 🔗 Debug Binary | [Download](${{ env.ARTIFACT_URL }}) | + | 🔗 Latest commit | [${{ env.LATEST_COMMIT }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) | + EOF + ) # Post Comment gh pr comment ${{ github.event.pull_request.number }} --body "$COMMENT" From 2dafb5c9c1f608a2330bbd51289a7a600213b73f Mon Sep 17 00:00:00 2001 From: Scai <59282365+alexevladgabriel@users.noreply.github.com> Date: Wed, 8 Jan 2025 00:37:19 +0000 Subject: [PATCH 08/10] chore: update existing comment --- .github/workflows/push.yaml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index 330bdac..d270cc2 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -90,6 +90,7 @@ jobs: run: | if [[ "${{ github.event_name }}" == "pull_request" ]]; then TITLE="${{ github.event.pull_request.title }}" + PR_NUMBER=${{ github.event.pull_request.number }} else TITLE="main branch" fi @@ -105,4 +106,21 @@ jobs: ) # Post Comment - gh pr comment ${{ github.event.pull_request.number }} --body "$COMMENT" + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + # Look for an existing comment + COMMENT_ID=$(gh api repos/${{ github.repository }}/issues/$PR_NUMBER/comments \ + --jq '.[] | select(.body | contains("✅ **Build successfully for")) | .id') + + if [ -z "$COMMENT_ID" ]; then + # Create a new comment if none exists + gh pr comment $PR_NUMBER --body "$COMMENT" + else + # Update the existing comment + gh api repos/${{ github.repository }}/issues/comments/$COMMENT_ID \ + --method PATCH \ + -f body="$COMMENT" + fi + else + # Log the comment for main branch + echo "$COMMENT" + fi From 0e65c0a9a98b90017d7214fcb9bfa1a3b0f7ed29 Mon Sep 17 00:00:00 2001 From: Scai <59282365+alexevladgabriel@users.noreply.github.com> Date: Wed, 8 Jan 2025 00:41:33 +0000 Subject: [PATCH 09/10] chore: add last go version to matrix --- .github/workflows/push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index d270cc2..0fcf40b 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -21,7 +21,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-22.04] - go: [1.21] + go: [1.21, 1.23.4] node: [21] goos: [linux] goarch: [arm] From 57fbee1490c6b36df4c915e3c3d4591ecd74a400 Mon Sep 17 00:00:00 2001 From: Scai <59282365+alexevladgabriel@users.noreply.github.com> Date: Wed, 8 Jan 2025 00:51:44 +0000 Subject: [PATCH 10/10] chore: remove unnecessary actions --- .github/workflows/release.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c9ea4cd..eea90dd 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -59,10 +59,6 @@ jobs: git config --local user.name "github-actions[bot]" git checkout -b ${BRANCH} git push -u origin ${BRANCH} - sed -i "s/var builtAppVersion = \".*\"/var builtAppVersion = \"${REF:11}\"/" ota.go - git add ota.go - git commit -m "bump version for release" - git push - name: Create Release id: create_release