Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests with SHA retrieval #3

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"no-console": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/no-require-imports": "error",
Expand Down
33 changes: 22 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,33 @@ name: "build-test"
on: # rebuild any PRs and main branch changes
pull_request:
push:
branches:
- master
- 'releases/*'

jobs:
build: # make sure build/ci work properly
# build: # make sure build/ci work properly
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - run: |
# npm install
# npm run all
test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: |
npm install
npm run all
test: # make sure the action works on a clean machine without building
- uses: hmarr/[email protected]
- uses: actions/checkout@v2
- uses: ./
if: ${{ github.event_name == 'pull_request' }}
with:
path: '**/pmd.xml'
pr: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: hmarr/[email protected]
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: ./
with:
path: '**/pmd.xml'
if: ${{ github.event_name == 'pull_request' }}
with:
path: '**/pmd.xml'
ref: ${{ github.event.pull_request.head.sha }}
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ inputs:
Also when generating a new PAT, select the least scopes necessary.
[Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
default: ${{ github.token }}
ref:
description: >
The SHA to post the results to.
default: ${{ github.sha }}
runs:
using: 'node12'
main: 'dist/index.js'
Expand Down
27 changes: 24 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ var Inputs;
Inputs["Title"] = "title";
Inputs["Path"] = "path";
Inputs["Token"] = "token";
Inputs["Ref"] = "ref";
})(Inputs = exports.Inputs || (exports.Inputs = {}));


Expand Down Expand Up @@ -8458,11 +8459,31 @@ function run() {
function createCheck(name, title, annotations, numErrors) {
return __awaiter(this, void 0, void 0, function* () {
const octokit = github_1.getOctokit(core.getInput(constants_1.Inputs.Token));
const req = Object.assign(Object.assign({}, github_1.context.repo), { ref: github_1.context.sha });
const head_sha = core.getInput('ref', { required: true });
const req = Object.assign(Object.assign({}, github_1.context.repo), { ref: head_sha });
const run_id = Number(process.env['GITHUB_RUN_ID']);
const workflowRun = yield octokit.actions.getWorkflowRun(Object.assign(Object.assign({}, github_1.context.repo), { run_id }));
console.log('Workflow run: %o', workflowRun.data);
// Gotta love Github's crippled API
const checkSuiteUrl = workflowRun.data.check_suite_url;
const checkSuiteId = Number(checkSuiteUrl.substring(checkSuiteUrl.lastIndexOf('/') + 1));
core.info(`Posting check result for ${head_sha}`);
const suitesRes = yield octokit.checks.listSuitesForRef(req);
// const suitesById = indexBy(
// suite => String(suite.id),
// suitesRes.data.check_suites
// )
const res = yield octokit.checks.listForRef(req);
const existingCheckRun = res.data.check_runs.find(check => check.name === name);
const existingCheckRun = res.data.check_runs.find(check => check.name === name && check.check_suite.id === checkSuiteId);
if (existingCheckRun) {
console.log('Found existing check run %o', existingCheckRun);
}
else {
console.log(' The check suites are %o', suitesRes.data.check_suites);
}
if (!existingCheckRun) {
const createRequest = Object.assign(Object.assign({}, github_1.context.repo), { head_sha: github_1.context.sha, name, status: 'completed', conclusion: numErrors === 0 ? 'success' : 'neutral', output: {
const createRequest = Object.assign(Object.assign({}, github_1.context.repo), { head_sha,
name, status: 'completed', conclusion: numErrors === 0 ? 'success' : 'neutral', output: {
title,
summary: `${numErrors} violation(s) found`,
annotations
Expand Down
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export enum Inputs {
Name = 'name',
Title = 'title',
Path = 'path',
Token = 'token'
Token = 'token',
Ref = 'ref'
}
39 changes: 36 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,56 @@ async function createCheck(
numErrors: number
): Promise<void> {
const octokit = getOctokit(core.getInput(Inputs.Token))
const head_sha = core.getInput('ref', {required: true})
const req = {
...context.repo,
ref: context.sha
ref: head_sha
}

const run_id = Number(process.env['GITHUB_RUN_ID'])

const workflowRun = await octokit.actions.getWorkflowRun({
...context.repo,
run_id
})

console.log('Workflow run: %o', workflowRun.data)

// Gotta love Github's crippled API
const checkSuiteUrl = workflowRun.data.check_suite_url
const checkSuiteId = Number(
checkSuiteUrl.substring(checkSuiteUrl.lastIndexOf('/') + 1)
)

core.info(`Posting check result for ${head_sha}`)

const suitesRes = await octokit.checks.listSuitesForRef(req)
// const suitesById = indexBy(
// suite => String(suite.id),
// suitesRes.data.check_suites
// )

const res = await octokit.checks.listForRef(req)
const existingCheckRun = res.data.check_runs.find(
check => check.name === name
check => check.name === name && check.check_suite.id === checkSuiteId
)

if (existingCheckRun) {
console.log('Found existing check run %o', existingCheckRun)
} else {
console.log(' The check suites are %o', suitesRes.data.check_suites)
}

if (!existingCheckRun) {
const createRequest = {
...context.repo,
head_sha: context.sha,
head_sha,
name,
status: <const>'completed',
conclusion: numErrors === 0 ? <const>'success' : <const>'neutral',
check_suite : {
id : checkSuiteId
},
output: {
title,
summary: `${numErrors} violation(s) found`,
Expand Down