-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yaml
125 lines (120 loc) · 4.59 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: "pkgcheck"
description: "Test your package with {pkgcheck}."
branding:
icon: 'check-circle'
color: 'blue'
inputs:
ref:
description: "The ref to checkout and check. Set to empty string to skip checkout."
default: "${{ github.ref }}"
required: true
post-to-issue:
description: "Should the pkgcheck results be posted as an issue?"
# If you use the 'pull_request' trigger and the PR is from outside the repo
# (e.g. a fork), the job will fail due to permission issues
# if this is set to 'true'. The default will prevent this.
default: ${{ github.event_name != 'pull_request' }}
required: true
issue-title:
description: "Name for the issue containing the pkgcheck results. Will be created or updated."
# This will create a new issue for every branch, set it to something fixed
# to only create one issue that is updated via edits.
default: "pkgcheck results - ${{ github.ref_name }}"
required: true
summary-only:
description: "Only post the check summary to issue. Set to false to get the full results in the issue."
default: true
required: true
append-to-issue:
description: "Should issue results be appended to existing issue, or posted in new issues."
default: true
required: true
runs:
using: "composite"
steps:
- name: Checkout repo
if: ${{ inputs.ref != ''}}
uses: actions/checkout@v4
with:
ref: "${{ inputs.ref }}"
fetch-depth: 0
- uses: docker://ghcr.io/ropensci-review-tools/pkgcheck-action:latest
env:
GITHUB_TOKEN: ${{ github.token }}
id: pkgcheck
- uses: actions/upload-artifact@v4
with:
name: visual-network
path: "${{ steps.pkgcheck.outputs.visnet_path }}"
- uses: actions/upload-artifact@v4
with:
name: results
path: "${{ steps.pkgcheck.outputs.results }}"
- name: Check for active issue
id: get-id
if: ${{ inputs.post-to-issue}}
uses: actions/github-script@v5
with:
script: |
const bot_name = "github-actions[bot]"
const query = "repo:${{ github.repository }} is:issue is:open user:" + bot_name + " in:title ${{ inputs.issue-title }}"
const issues = await github.rest.search.issuesAndPullRequests({ q: query, sort: "created" })
let issue_nr
if(typeof issues === "undefined") {
issue_nr = -1
} else {
const issue = issues.data.items.find(e => e.title === "${{ inputs.issue-title }}" &&
e.state === "open" &&
e.user.login === bot_name
)
issue_nr = typeof issue === "undefined" ? -1 : issue.number
}
return issue_nr
- id: get-repo
if: ${{ inputs.post-to-issue}}
uses: actions/github-script@v7
with:
result-encoding: string
script: |
return "${{ github.repository }}".split("/", 2)[1]
- name: Create/Update Issue
uses: actions/github-script@v7
with:
script: |
const fs = require('fs')
const md_path = ("${{ inputs.summary-only }}" === "true" ? "${{ steps.pkgcheck.outputs.summary_md }}" : "${{ steps.pkgcheck.outputs.full_md }}").trim()
let issue_body;
try {
issue_body = fs.readFileSync(md_path, 'utf8')
} catch (err) {
console.error(err)
}
const owner = "${{ github.repository_owner }}"
const repo = "${{ steps.get-repo.outputs.result }}"
if (${{ steps.get-id.outputs.result != -1 && inputs.post-to-issue }}) {
if (${{ inputs.append-to-issue }}) {
github.rest.issues.createComment({
owner: owner,
repo: repo,
issue_number: "${{ steps.get-id.outputs.result }}",
body: issue_body
})
} else {
github.rest.issues.update({
owner: owner,
repo: repo,
issue_number: "${{ steps.get-id.outputs.result }}",
body: issue_body,
})
}
} else if (${{ steps.get-id.outputs.result == -1 && inputs.post-to-issue }}) {
github.rest.issues.create({
owner: owner,
repo: repo,
title: "${{ inputs.issue-title }}",
body: issue_body
})
}
- name: Fail if pkgcheck found problems
run: exit ${{ steps.pkgcheck.outputs.status }}
shell: bash