From 41882c4935c06997fbd3f4dc0a29f9f329005e51 Mon Sep 17 00:00:00 2001
From: JayaShakthi97
Date: Wed, 20 Mar 2024 15:26:59 +0530
Subject: [PATCH] Introduce changeset checker
---
.github/workflows/check-changeset.yml | 98 +++++++++++++++++++++++++++
.github/workflows/receive-pr.yml | 44 ++++++++++++
2 files changed, 142 insertions(+)
create mode 100644 .github/workflows/check-changeset.yml
create mode 100644 .github/workflows/receive-pr.yml
diff --git a/.github/workflows/check-changeset.yml b/.github/workflows/check-changeset.yml
new file mode 100644
index 00000000000..aae88e7ba59
--- /dev/null
+++ b/.github/workflows/check-changeset.yml
@@ -0,0 +1,98 @@
+# -------------------------------------------------------------------------------------
+#
+# Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+#
+# WSO2 LLC. licenses this file to you under the Apache License,
+# Version 2.0 (the "License"); you may not use this file except
+# in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# --------------------------------------------------------------------------------------
+
+# This workflow will check if a submitted PR has changesets.
+
+name: 🦋 Check for Changeset
+
+on:
+ workflow_run:
+ workflows: ["Receive PR"]
+ types:
+ - completed
+
+env:
+ GH_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }}
+
+jobs:
+ process-pr:
+ runs-on: ubuntu-latest
+ if: >
+ github.event.workflow_run.event == 'pull_request' &&
+ github.event.workflow_run.conclusion == 'success'
+ steps:
+ - name: Download PR Number Artifact
+ uses: actions/github-script@v3.1.0
+ with:
+ script: |
+ const artifacts = await github.actions.listWorkflowRunArtifacts({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ run_id: ${{ github.event.workflow_run.id }},
+ });
+ const matchArtifact = artifacts.data.artifacts.find(artifact => artifact.name === "pr-number");
+ const download = await github.actions.downloadArtifact({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ artifact_id: matchArtifact.id,
+ archive_format: 'zip',
+ });
+ const fs = require('fs');
+ fs.writeFileSync('${{github.workspace}}/pr-number.zip', Buffer.from(download.data));
+
+ - name: Extract PR Number Artifact
+ run: unzip pr-number.zip
+
+ - name: 💬 Add Changeset Comment
+ uses: actions/github-script@v3.1.0
+ with:
+ github-token: ${{ env.GH_TOKEN }}
+ script: |
+ const PR_NUMBER = context.payload.pull_request.number;
+ const REPO_OWNER = context.repo.owner;
+ const REPO_NAME = context.repo.repo;
+ const PR_HEAD_SHA = context.payload.pull_request.head.sha;
+
+ const files = await github.pulls.listFiles({
+ owner: REPO_OWNER,
+ repo: REPO_NAME,
+ pull_number: PR_NUMBER,
+ });
+
+ const CHANGED_FILES = files.data.map(file => file.filename);
+ console.log("CHANGED_FILES_URL: https://api.github.com/repos/" + REPO_NAME + "/pulls/" + PR_NUMBER + "/files");
+ console.log("CHANGED_FILES:", CHANGED_FILES);
+
+ const CHANGES_COUNT = CHANGED_FILES.filter(filename => /^\.changeset\/.*\.md$/.test(filename)).length;
+ console.log("CHANGES_COUNT:", CHANGES_COUNT);
+
+ let COMMENT;
+ if (CHANGES_COUNT > 0) {
+ COMMENT = `🦋 Changeset detected
Latest commit: ${PR_HEAD_SHA}
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
`;
+ } else {
+ COMMENT = `⚠️ No Changeset found
Latest commit: ${PR_HEAD_SHA}
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go.
If these changes should result in a version bump, you need to add a changeset.
Click here to learn what changesets are, and how to add one`;
+ }
+
+ await github.issues.createComment({
+ owner: REPO_OWNER,
+ repo: REPO_NAME,
+ issue_number: PR_NUMBER,
+ body: COMMENT,
+ });
diff --git a/.github/workflows/receive-pr.yml b/.github/workflows/receive-pr.yml
new file mode 100644
index 00000000000..1b0e95a9846
--- /dev/null
+++ b/.github/workflows/receive-pr.yml
@@ -0,0 +1,44 @@
+# -------------------------------------------------------------------------------------
+#
+# Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+#
+# WSO2 LLC. licenses this file to you under the Apache License,
+# Version 2.0 (the "License"); you may not use this file except
+# in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# -------------------------------------------------------------------------------------
+
+name: Receive PR
+
+on:
+ pull_request:
+ branches: [master]
+
+jobs:
+ save-pr-information:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout Repository
+ uses: actions/checkout@v3
+
+ - name: Display PR Information
+ run: echo "PR Number \#${{github.event.number}}"
+
+ - name: Save PR Number for Later Use
+ run: echo "${{github.event.number}}" > PR_NUMBER
+
+ - name: Upload PR Number as Artifact
+ uses: actions/upload-artifact@v3
+ with:
+ name: pr-number
+ path: PR_NUMBER