From edd280073014835dd3087613ba1a27a54479926e Mon Sep 17 00:00:00 2001 From: Hare Sudhan Date: Tue, 9 Jul 2024 22:41:41 -0500 Subject: [PATCH] update scripts --- .github/actions/run-atomics/action.yml | 24 ++++++- .github/workflows/assign-labels.yml | 86 ++++++++++++++++++++++++++ .github/workflows/validate-atomics.yml | 38 ++---------- 3 files changed, 114 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/assign-labels.yml diff --git a/.github/actions/run-atomics/action.yml b/.github/actions/run-atomics/action.yml index f1db43d423..0b4cd23c75 100644 --- a/.github/actions/run-atomics/action.yml +++ b/.github/actions/run-atomics/action.yml @@ -2,9 +2,29 @@ name: "Install and Run Atomics" runs: using: "composite" steps: - - uses: actions/download-artifact@v4 + - name: download-artifact + uses: actions/github-script@v7 with: - name: changedfiles.json + script: | + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { + return artifact.name == "changedfiles.json" + })[0]; + let download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + let fs = require('fs'); + fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/changedfiles.zip`, Buffer.from(download.data)); + + - name: unzip-artifact + run: unzip changedfiles.zip - name: Run atomics shell: pwsh diff --git a/.github/workflows/assign-labels.yml b/.github/workflows/assign-labels.yml new file mode 100644 index 0000000000..3678688d29 --- /dev/null +++ b/.github/workflows/assign-labels.yml @@ -0,0 +1,86 @@ +name: assign-labels + +on: + workflow_run: + workflows: ["validate-atomics"] + types: + - completed + +jobs: + assign-labels: + runs-on: ubuntu-latest + steps: + - name: download-artifact + uses: actions/github-script@v7 + with: + script: | + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { + return artifact.name == "labels.json" + })[0]; + let download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + let fs = require('fs'); + fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/labels.zip`, Buffer.from(download.data)); + + - name: unzip-artifact + run: unzip labels.zip + + - name: assign-labels-and-reviewers + uses: actions/github-script@v7 + with: + script: | + let fs = require('fs'); + const obj = JSON.parse(fs.readFileSync('./labels.json')); + console.log(obj) + if(obj.labels.length > 0){ + await github.rest.issues.addLabels({ + issue_number: obj.pr, + owner: context.repo.owner, + repo: context.repo.repo, + labels: obj.labels + }) + } + if(obj.maintainers.length > 0){ + await github.rest.issues.addAssignees({ + issue_number: obj.pr, + owner: context.repo.owner, + repo: context.repo.repo, + assignees: obj.maintainers + }); + } + + run-windows-atomics: + if: ${{ contains(github.event.pull_request.labels.*.name, 'windows') }} + runs-on: windows-latest + needs: + - upload + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/run-atomics + + run-macos-atomics: + if: ${{ contains(github.event.pull_request.labels.*.name, 'macos') }} + runs-on: macos-latest + needs: + - upload + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/run-atomics + + run-linux-atomics: + if: ${{ contains(github.event.pull_request.labels.*.name, 'linux') }} + runs-on: ubuntu-latest + needs: + - upload + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/run-atomics \ No newline at end of file diff --git a/.github/workflows/validate-atomics.yml b/.github/workflows/validate-atomics.yml index 7abcbfb0fb..d7a605bbd3 100644 --- a/.github/workflows/validate-atomics.yml +++ b/.github/workflows/validate-atomics.yml @@ -1,14 +1,10 @@ name: validate-atomics on: - pull_request_target: + pull_request: branches: - master -permissions: - pull-requests: write - issues: write - jobs: validate-atomics: runs-on: ubuntu-latest @@ -75,32 +71,10 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: changedfiles.json + name: labels.json path: atomic_red_team/pr/ - run-windows-atomics: - if: ${{ contains(github.event.pull_request.labels.*.name, 'windows') }} - runs-on: windows-latest - needs: - - upload - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/run-atomics - - run-macos-atomics: - if: ${{ contains(github.event.pull_request.labels.*.name, 'macos') }} - runs-on: macos-latest - needs: - - upload - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/run-atomics - - run-linux-atomics: - if: ${{ contains(github.event.pull_request.labels.*.name, 'linux') }} - runs-on: ubuntu-latest - needs: - - upload - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/run-atomics \ No newline at end of file + - uses: actions/upload-artifact@v4 + with: + name: changedfiles.json + path: atomic_red_team/pr/