Skip to content

Commit

Permalink
update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberbuff committed Jul 10, 2024
1 parent 5a89cc4 commit edd2800
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 34 deletions.
24 changes: 22 additions & 2 deletions .github/actions/run-atomics/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
86 changes: 86 additions & 0 deletions .github/workflows/assign-labels.yml
Original file line number Diff line number Diff line change
@@ -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
38 changes: 6 additions & 32 deletions .github/workflows/validate-atomics.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
- uses: actions/upload-artifact@v4
with:
name: changedfiles.json
path: atomic_red_team/pr/

0 comments on commit edd2800

Please sign in to comment.