From 4cbb73a053830cb256f55bc17bbfd2d95968ade6 Mon Sep 17 00:00:00 2001 From: Jakob Krantz Date: Tue, 5 Nov 2024 21:36:40 +0100 Subject: [PATCH 1/5] ci: Run CI on pull requests also. --- .github/workflows/production.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml index bfdd95c..7b06af8 100644 --- a/.github/workflows/production.yml +++ b/.github/workflows/production.yml @@ -5,6 +5,7 @@ on: pull_request_target: types: - closed + - pull_request jobs: build: From 437442cf6d8e5d8deca42b91d65507b627238a42 Mon Sep 17 00:00:00 2001 From: Jakob Krantz Date: Tue, 5 Nov 2024 21:45:12 +0100 Subject: [PATCH 2/5] ci: Fix kidiff output resolution to a valid range. --- .github/workflows/diff.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/diff.yml b/.github/workflows/diff.yml index fa9cdeb..1dd49ee 100644 --- a/.github/workflows/diff.yml +++ b/.github/workflows/diff.yml @@ -25,11 +25,11 @@ jobs: - name: Create schematics diff run: | - kicad-diff.py original/project/ZSWatch.kicad_sch modified/project/ZSWatch.kicad_sch --diff_mode red_green --all_pages --output_dir diff-schematics --no_reader --keep_pngs --resolution 500 + kicad-diff.py original/project/ZSWatch.kicad_sch modified/project/ZSWatch.kicad_sch --diff_mode red_green --all_pages --output_dir diff-schematics --no_reader --keep_pngs - name: Create layout diff run: | - kicad-diff.py original/project/ZSWatch.kicad_pcb modified/project/ZSWatch.kicad_pcb --diff_mode red_green --all_pages --output_dir diff-layout --no_reader --keep_pngs --resolution 500 + kicad-diff.py original/project/ZSWatch.kicad_pcb modified/project/ZSWatch.kicad_pcb --diff_mode red_green --all_pages --output_dir diff-layout --no_reader --keep_pngs - name: Upload Layout Diff uses: actions/upload-artifact@v4 From 6cab9a0de48c3e0c1d54445f58c87d5ecca60b74 Mon Sep 17 00:00:00 2001 From: Jakob Krantz Date: Tue, 5 Nov 2024 22:03:18 +0100 Subject: [PATCH 3/5] ci: Update uploaded artifact name in diff.yml --- .github/workflows/diff.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/diff.yml b/.github/workflows/diff.yml index 1dd49ee..07d5431 100644 --- a/.github/workflows/diff.yml +++ b/.github/workflows/diff.yml @@ -25,22 +25,22 @@ jobs: - name: Create schematics diff run: | - kicad-diff.py original/project/ZSWatch.kicad_sch modified/project/ZSWatch.kicad_sch --diff_mode red_green --all_pages --output_dir diff-schematics --no_reader --keep_pngs + kicad-diff.py original/project/ZSWatch.kicad_sch modified/project/ZSWatch.kicad_sch --diff_mode red_green --all_pages --output_dir diff-schematics --no_reader --keep_pngs --resolution 400 - name: Create layout diff run: | - kicad-diff.py original/project/ZSWatch.kicad_pcb modified/project/ZSWatch.kicad_pcb --diff_mode red_green --all_pages --output_dir diff-layout --no_reader --keep_pngs + kicad-diff.py original/project/ZSWatch.kicad_pcb modified/project/ZSWatch.kicad_pcb --diff_mode red_green --all_pages --output_dir diff-layout --no_reader --keep_pngs --resolution 400 - name: Upload Layout Diff uses: actions/upload-artifact@v4 with: - name: "diff-layout-master-${{ github.ref_name }}" + name: "diff-layout-${{ github.ref_name }}" path: diff-layout if-no-files-found: ignore - name: Upload Schematics Diff uses: actions/upload-artifact@v4 with: - name: "diff-schematics-master-${{ github.ref_name }}" + name: "diff-schematics-${{ github.ref_name }}" path: diff-schematics if-no-files-found: ignore From d32e6cb1f50216d254e6c05323659fdad58c6c80 Mon Sep 17 00:00:00 2001 From: Jakob Krantz Date: Tue, 5 Nov 2024 22:18:06 +0100 Subject: [PATCH 4/5] ci: Add comment to PR with link do the Kidiff of the changes. --- .github/workflows/comment_pr_diff.yml | 77 +++++++++++++++++++++++++++ .github/workflows/production.yml | 1 + 2 files changed, 78 insertions(+) create mode 100644 .github/workflows/comment_pr_diff.yml diff --git a/.github/workflows/comment_pr_diff.yml b/.github/workflows/comment_pr_diff.yml new file mode 100644 index 0000000..16c6d4b --- /dev/null +++ b/.github/workflows/comment_pr_diff.yml @@ -0,0 +1,77 @@ +# comment_pr_diff.yml +# From https://github.com/orgs/community/discussions/51403z +name: Comment Artifact Diff files URL on PR + +on: + workflow_run: + types: + - "completed" + workflows: + - "Diff" + +jobs: + comment-on-pr: + if: github.event.workflow_run.conclusion == 'success' + runs-on: ubuntu-latest + steps: + - name: Test + run: | + pwd + + - name: Get Artifact URL & PR Info + env: + GITHUB_TOKEN: ${{ github.token }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }} + run: | + + PREVIOUS_JOB_ID=$(jq -r '.id' <<< "$WORKFLOW_RUN_EVENT_OBJ") + echo "Previous Job ID: $PREVIOUS_JOB_ID" + echo "PREVIOUS_JOB_ID=$PREVIOUS_JOB_ID" >> "$GITHUB_ENV" + + ARTIFACT_URL=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" \ + --jq ".artifacts.[] | + select(.workflow_run.id==${PREVIOUS_JOB_ID}) | + select(.expired==false) | + .archive_download_url") + + echo "ARTIFACT URL: $ARTIFACT_URL" + echo "ARTIFACT_URL=$ARTIFACT_URL" >> "$GITHUB_ENV" + + PR_NUMBER=$(jq -r '.pull_requests[0].number' \ + <<< "$WORKFLOW_RUN_EVENT_OBJ") + + echo "PR Number: $PR_NUMBER" + echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV" + + HEAD_SHA=$(jq -r '.pull_requests[0].head.sha' \ + <<< "$WORKFLOW_RUN_EVENT_OBJ") + + echo "Head sha: $HEAD_SHA" + echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV" + + - name: Update Comment + env: + JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/\ + runs/${{ env.PREVIOUS_JOB_ID }}" + HEAD_SHA: ${{ env.HEAD_SHA }} + uses: peter-evans/create-or-update-comment@v2 + with: + issue-number: ${{ env.PR_NUMBER }} + body: |- + ## Diff preview files are ready! + + [![badge]]($JOB_PATH) + + You can find files attached to the below linked Workflow Run URL (Logs). + + | Name | Link + -------------------------------------------------------------------- + | Commit | ${{ env.HEAD_SHA }} + + | Logs | ${{ env.JOB_PATH }} + + | Jar Files | ${{ env. ARTIFACT_URL }} + + [badge]: https://img.shields.io/badge/Build-Success!-3fb950?logo=github&style=for-the-badge \ No newline at end of file diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml index 7b06af8..86828f3 100644 --- a/.github/workflows/production.yml +++ b/.github/workflows/production.yml @@ -6,6 +6,7 @@ on: types: - closed - pull_request + - push jobs: build: From 88270b26ee802d9ddaba40c85c1bcf257422d047 Mon Sep 17 00:00:00 2001 From: Jakob Krantz Date: Tue, 5 Nov 2024 22:47:02 +0100 Subject: [PATCH 5/5] WIP --- .github/workflows/comment_pr_diff.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/comment_pr_diff.yml b/.github/workflows/comment_pr_diff.yml index 16c6d4b..2ed66e0 100644 --- a/.github/workflows/comment_pr_diff.yml +++ b/.github/workflows/comment_pr_diff.yml @@ -60,7 +60,7 @@ jobs: with: issue-number: ${{ env.PR_NUMBER }} body: |- - ## Diff preview files are ready! + ## Diff ASDF preview files are ready! [![badge]]($JOB_PATH)