Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .github/workflows/arm-auto-signoff.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: ARM Auto SignOff

on:
Expand All @@ -16,25 +16,6 @@
workflow_run:
workflows: ["ARM Incremental TypeSpec"]
types: [completed]
# 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:
actions: read
Expand All @@ -51,7 +32,6 @@
# issue_comment:edited - filter to only PR comments containing "next steps to merge",
# a signal that checks like "Swagger LintDiff" or "Swagger Avocado" status may have changed
if: |
github.event_name == 'workflow_dispatch' ||
github.event_name == 'workflow_run' ||
(github.event_name == 'pull_request_target' &&
(github.event.action == 'labeled' ||
Expand Down Expand Up @@ -96,11 +76,6 @@
const { default: getLabelAction } =
await import('${{ github.workspace }}/.github/workflows/src/arm-auto-signoff.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: |
fromJson(steps.get-label-action.outputs.result).labelAction == 'add' ||
Expand Down
13 changes: 1 addition & 12 deletions .github/workflows/src/arm-auto-signoff.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// @ts-check

import { setEquals } from "../../shared/src/equality.js";
Expand All @@ -12,18 +12,7 @@
* @returns {Promise<{labelAction: LabelAction, issueNumber: number}>}
*/
export default async function getLabelAction({ github, context, core }) {
let owner = process.env.OWNER || "";
let repo = process.env.REPO || "";
let issue_number = parseInt(process.env.ISSUE_NUMBER || "");
let head_sha = process.env.HEAD_SHA || "";

if (!owner || !repo || !issue_number || !head_sha) {
let inputs = await extractInputs(github, context, core);
owner = owner || inputs.owner;
repo = repo || inputs.repo;
issue_number = issue_number || inputs.issue_number;
head_sha = head_sha || inputs.head_sha;
}
const { owner, repo, issue_number, head_sha } = await extractInputs(github, context, core);

return await getLabelActionImpl({
owner,
Expand Down
14 changes: 1 addition & 13 deletions .github/workflows/src/update-labels.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// @ts-check

import { extractInputs } from "../src/context.js";
Expand All @@ -7,19 +7,7 @@
* @param {import('@actions/github-script').AsyncFunctionArguments} AsyncFunctionArguments
*/
export default async function updateLabels({ github, context, core }) {
let owner = process.env.OWNER;
let repo = process.env.REPO;
let issue_number = parseInt(process.env.ISSUE_NUMBER || "");
let run_id = parseInt(process.env.RUN_ID || "");

if (!owner || !repo || !(issue_number || run_id)) {
let inputs = await extractInputs(github, context, core);
owner = owner || inputs.owner;
repo = repo || inputs.repo;
issue_number = issue_number || inputs.issue_number;
run_id = run_id || inputs.run_id;
}

const { owner, repo, issue_number, run_id } = await extractInputs(github, context, core);
await updateLabelsImpl({ owner, repo, issue_number, run_id, github, core });
}

Expand Down
101 changes: 0 additions & 101 deletions .github/workflows/test/update-labels.test.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,9 @@
import { describe, expect, it } from "vitest";
import { PER_PAGE_MAX } from "../src/github.js";
import updateLabels, { updateLabelsImpl } from "../src/update-labels.js";
import { createMockCore, createMockGithub, createMockRequestError } from "./mocks.js";

describe("updateLabels", () => {
it("loads inputs from env", async () => {
const github = createMockGithub();
github.rest.actions.listWorkflowRunArtifacts.mockResolvedValue({
data: {
artifacts: [{ name: "label-foo=true" }],
},
});

try {
process.env.OWNER = "TestRepoOwnerLoginEnv";
process.env.REPO = "TestRepoNameEnv";
process.env.ISSUE_NUMBER = "123";
process.env.RUN_ID = "456";

await expect(
updateLabels({
github: github,
context: null,
core: createMockCore(),
}),
).resolves.toBeUndefined();
} finally {
delete process.env.OWNER;
delete process.env.REPO;
delete process.env.ISSUE_NUMBER;
delete process.env.RUN_ID;
}

expect(github.rest.actions.listWorkflowRunArtifacts).toBeCalledWith({
owner: "TestRepoOwnerLoginEnv",
repo: "TestRepoNameEnv",
run_id: 456,
per_page: PER_PAGE_MAX,
});
expect(github.rest.issues.addLabels).toBeCalledWith({
owner: "TestRepoOwnerLoginEnv",
repo: "TestRepoNameEnv",
issue_number: 123,
labels: ["foo"],
});
expect(github.rest.issues.removeLabel).toBeCalledTimes(0);
});

it("loads inputs from context", async () => {
const github = createMockGithub();
github.rest.actions.listWorkflowRunArtifacts.mockResolvedValue({
Expand Down Expand Up @@ -96,64 +53,6 @@
});
expect(github.rest.issues.removeLabel).toBeCalledTimes(0);
});

it("loads inputs from env and context", async () => {
const github = createMockGithub();
github.rest.actions.listWorkflowRunArtifacts.mockResolvedValue({
data: {
artifacts: [{ name: "label-foo=true" }],
},
});

const context = {
eventName: "workflow_run",
payload: {
action: "completed",
workflow_run: {
event: "pull_request",
head_sha: "abc123",
id: 456,
repository: {
name: "TestRepoName",
owner: {
login: "TestRepoOwnerLogin",
},
},
pull_requests: [{ number: 123 }],
},
},
};

try {
process.env.OWNER = "TestRepoOwnerLoginEnv";
process.env.REPO = "TestRepoNameEnv";

await expect(
updateLabels({
github: github,
context: context,
core: createMockCore(),
}),
).resolves.toBeUndefined();
} finally {
delete process.env.OWNER;
delete process.env.REPO;
}

expect(github.rest.actions.listWorkflowRunArtifacts).toBeCalledWith({
owner: "TestRepoOwnerLoginEnv",
repo: "TestRepoNameEnv",
run_id: 456,
per_page: PER_PAGE_MAX,
});
expect(github.rest.issues.addLabels).toBeCalledWith({
owner: "TestRepoOwnerLoginEnv",
repo: "TestRepoNameEnv",
issue_number: 123,
labels: ["foo"],
});
expect(github.rest.issues.removeLabel).toBeCalledTimes(0);
});
});

describe("updateLabelsImpl", () => {
Expand Down
25 changes: 0 additions & 25 deletions .github/workflows/update-labels.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: Update Labels

on:
Expand All @@ -9,26 +9,6 @@
workflows:
["ARM Auto SignOff", "SDK Breaking Change Labels", "SDK Suppressions", "TypeSpec Requirement"]
types: [completed]
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
# simulate pull_request trigger
issue_number:
description: The number that identifies the issue.
required: false
type: number
# simulate workflow_run trigger
run_id:
description: The unique identifier of the workflow run.
required: false
type: number

permissions:
actions: read
Expand All @@ -52,11 +32,6 @@

- name: Update Labels
uses: actions/github-script@v7
env:
OWNER: ${{ inputs.owner }}
REPO: ${{ inputs.repo }}
ISSUE_NUMBER: ${{ inputs.issue_number }}
RUN_ID: ${{ inputs.run_id }}
with:
script: |
const { default: updateLabels } =
Expand Down
Loading