Skip to content

Commit

Permalink
[EngSys] Add check ARMAutoSignoffPreview (#32457)
Browse files Browse the repository at this point in the history
- Fixes #32173
  • Loading branch information
mikeharder authored Feb 10, 2025
1 parent 7797d20 commit 8abab3c
Show file tree
Hide file tree
Showing 13 changed files with 916 additions and 21 deletions.
125 changes: 125 additions & 0 deletions .github/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .github/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"@types/github-script": "github:actions/github-script",
"@octokit/webhooks-types": "^7.5.1",
"@vitest/coverage-v8": "^3.0.5",
"memfs": "^4.17.0",
"prettier": "^3.3.3",
"vitest": "^3.0.5"
},
Expand Down
4 changes: 2 additions & 2 deletions .github/src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export async function extractInputs(github, context, core) {
// empty for non-fork PRs.
issue_number = pull_requests[0].number;
} else {
// For fork PRs, we must call an API in the head repository to get the PR number in the target repository
// For fork PRs, we must call an API in the head repository to get the PR number in the base repository

// Owner and repo for the PR head (at least one should differ from target for fork PRs)
// Owner and repo for the PR head (at least one should differ from base for fork PRs)
const head_owner = payload.workflow_run.head_repository.owner.login;
const head_repo = payload.workflow_run.head_repository.name;
const head_sha = payload.workflow_run.head_sha;
Expand Down
17 changes: 17 additions & 0 deletions .github/src/label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @ts-check

// @ts-nocheck Prevent false positive for duplicate typedef and const names
/**
* @typedef {"none" | "add" | "remove"} LabelAction
*/

/**
* @readonly
* @enum {LabelAction}
*/
export const LabelAction = Object.freeze({
None: "none",
Add: "add",
Remove: "remove",
});
// @ts-check
24 changes: 24 additions & 0 deletions .github/test/mocks.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
import { vi } from "vitest";

// Partial mock of `github` parameter passed into github-script actions
export function createMockGithub() {
return {
rest: {
actions: {
listWorkflowRunArtifacts: vi
.fn()
.mockResolvedValue({ data: { artifacts: [] } }),
},
checks: {
listForRef: vi.fn().mockResolvedValue({ data: { check_runs: [] } }),
},
issues: {
addLabels: vi.fn(),
listLabelsOnIssue: vi.fn().mockRejectedValue({ data: [] }),
removeLabel: vi.fn(),
},
},
};
}

// Partial mock of `core` parameter passed into to github-script actions
export function createMockCore() {
return {
debug: vi.fn(console.debug),
info: vi.fn(console.log),
setOutput: vi.fn((name, value) =>
console.log(`setOutput('${name}', '${value}')`),
),
};
}
74 changes: 74 additions & 0 deletions .github/workflows/arm-auto-signoff-preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: ARM Auto Signoff (Preview)

on:
check_suite:
# Depends on check_run status, so must re-evaluate whenever a check_suite is completed.
# Could instead trigger on check_run events, but I think this is unnecessarily noisy.
types: [completed]
pull_request:
types:
# Depends on labels, so must re-evaluate whenever a label is manually added or removed.
- labeled
- unlabeled
# Depends on changed files and check_run status, so must re-evaluate whenever either could change
- opened
- reopened
- synchronize
# For manual testing
workflow_dispatch:
inputs:
owner:
description: The account owner of the repository. The name is not case sensitive.
required: true
type: string
repo:
description: The name of the repository without the .git extension. The name is not case sensitive.
required: true
type: string
issue_number:
description: The number of the pull request.
required: true
type: string
head_sha:
description: The SHA of the commit.
required: true
type: string

permissions:
contents: read

jobs:
arm-auto-signoff-preview:
name: ARM Auto Signoff (Preview)

runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v4
with:
# Required to determine files changed in PR
fetch-depth: 2

# Output is "none" for no-op, "add" to add label, and "remove" to remove label
- id: get-label-action
name: ARM Auto Signoff (Preview)
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const { default: getLabelAction } =
await import('${{ github.workspace }}/.github/workflows/src/arm-auto-signoff-preview.js');
return await getLabelAction({ github, context, core });
env:
OWNER: ${{ inputs.owner }}
REPO: ${{ inputs.repo }}
ISSUE_NUMBER: ${{ inputs.issue_number }}
HEAD_SHA: ${{ inputs.head_sha }}

- if: ${{ steps.get-label-action.outputs.result == 'add' || steps.get-label-action.outputs.result == 'remove' }}
name: Upload artifact with results
uses: ./.github/actions/add-label-artifact
with:
name: "ARMAutoSignoffPreview"
# Convert "add/remove" to "true/false"
value: "${{ steps.get-label-action.outputs.result == 'add' }}"
Loading

0 comments on commit 8abab3c

Please sign in to comment.