Skip to content

Commit 54bbfb9

Browse files
author
astrid.sapphire
committed
maint: add workflows
1 parent 893e3af commit 54bbfb9

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Check contribution
2+
3+
on:
4+
pull_request_target:
5+
branches:
6+
- main
7+
types: [opened, ready_for_review]
8+
9+
permissions:
10+
contents: read
11+
pull-requests: write
12+
issues: write
13+
14+
jobs:
15+
check:
16+
if: github.repository == 'ServiceNowDevProgram/ActionPack'
17+
runs-on: ubuntu-latest
18+
name: Check PR
19+
steps:
20+
- name: Shallow checkout
21+
uses: actions/checkout@v5
22+
with:
23+
ref: ${{ github.event.pull_request.base.sha }}
24+
fetch-depth: 0
25+
26+
- name: Detect allowed file changes
27+
id: changes
28+
uses: tj-actions/changed-files@823fcebdb31bb35fdf2229d9f769b400309430d0 # v46
29+
with:
30+
base_sha: ${{ github.event.pull_request.base.sha }}
31+
ref: ${{ github.event.pull_request.head.sha }}
32+
33+
files: |
34+
b812ceb69337a210633378917cba10bc/checksum.txt
35+
b812ceb69337a210633378917cba10bc/update/sys_hub_action_type_definition_*.xml
36+
37+
- name: Handle inappropriate contribution
38+
if: steps.changes.outputs.only_changed != 'true'
39+
uses: actions/github-script@v8
40+
with:
41+
script: |
42+
const {owner, repo} = context.repo;
43+
const pr = context.payload.pull_request.number;
44+
const label = 'non-compliant';
45+
46+
// Ensure label exists (create if missing)
47+
try {
48+
await github.rest.issues.getLabel({owner, repo, name: label});
49+
} catch (e) {
50+
if (e.status === 404) {
51+
await github.rest.issues.createLabel({owner, repo, name: label, color: 'B66B02', description: 'PR violates CONTRIBUTING rules'});
52+
} else {
53+
throw e;
54+
}
55+
}
56+
57+
console.log(`Non-compliant: ${nonCompliant}`);
58+
console.log(`All changed: ${allChanged}`);
59+
60+
const body = [
61+
'🚫 **Unexpected files changed in PR**',
62+
'',
63+
'Thank you for your contribution. However, it seems that the file changes in this Pull Request are incorrect or invalid.',
64+
'Please see the description of the unexpected file changes below. Contributions must be correct, valid, and align with the [CONTRIBUTING.md](CONTRIBUTING.md) for this repo.',
65+
'This pull request modifies files *outside* the allowed paths/patterns.',
66+
'',
67+
'**Allowed patterns:**',
68+
'```',
69+
'b812ceb69337a210633378917cba10bc/checksum.txt',
70+
'b812ceb69337a210633378917cba10bc/update/sys_hub_action_type_definition_*.xml',
71+
'```',
72+
'',
73+
'Closing this for now. Once you make additional changes, feel free to re-open this Pull Request or create a new one.',
74+
'',
75+
'If you feel that this PR should be accepted in its current state, please reach out to Astrid Sapphire (SapphicFire) on GitHub, or in the SNDevs Slack Hacktoberfest channel.',
76+
].join('\n');
77+
78+
await github.rest.issues.addLabels({owner, repo, issue_number: pr, labels: [label]});
79+
await github.rest.issues.createComment({owner, repo, issue_number: pr, body});
80+
await github.rest.pulls.update({owner, repo, pull_number: pr, state: 'closed'});
81+
82+
- name: Fail if non-compliant
83+
if: steps.changes.outputs.only_changed != 'true'
84+
run: |
85+
echo "Non-compliant file changes were made."
86+
exit 1
87+
88+
- name: Handle appropriate contribution
89+
if: steps.changes.outputs.only_changed == 'true'
90+
uses: actions/github-script@v8
91+
with:
92+
script: |
93+
const {owner, repo} = context.repo;
94+
const pr = context.payload.pull_request.number;
95+
96+
const body = [
97+
'✅ **Valid PR for ActionPack**',
98+
'',
99+
'Thank you for your contribution. This PR complies with the [CONTRIBUTING.md](CONTRIBUTING.md).',
100+
'A maintainer will review this shortly. In the meantime, Happy Hacking!',
101+
].join('\n');
102+
103+
await github.rest.issues.createComment({owner, repo, issue_number: pr, body});
104+
105+
- name: Succeed for compliant
106+
if: steps.changes.outputs.only_changed == 'true'
107+
run: |
108+
echo "Compliant file changes were made."
109+
exit 0

.github/workflows/hacktrack.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#This file is for ServiceNow Dev Program Hacktoberfest Tracking and can be ignored or deleted.
2+
3+
name: Record Hacktrack Event
4+
on:
5+
push:
6+
branches: main
7+
fork:
8+
branches: main
9+
issues:
10+
types: [opened, closed]
11+
branches: main
12+
pull_request_target:
13+
types: [opened, closed]
14+
branches: main
15+
jobs:
16+
deployment:
17+
if: github.repository == 'ServiceNowDevProgram/ActionPack'
18+
runs-on: ubuntu-latest
19+
steps:
20+
# - name: Log payload
21+
# env:
22+
# GITHUB_CONTEXT: ${{ toJson(github) }}
23+
# run: |
24+
# echo "$GITHUB_CONTEXT"
25+
- name: Contact DPR
26+
id: myRequest
27+
uses: fjogeleit/http-request-action@v1.8.1
28+
with:
29+
url: ${{ format('https://{0}.service-now.com/api/x_snc_hacktrack/hacktrack', secrets.HT_INSTANCE_NAME) }}
30+
method: 'POST'
31+
contentType: application/json
32+
data: ${{ toJson(github) }}
33+
username: ${{ secrets.DPRD_USERNAME }}
34+
password: ${{ secrets.DPRD_PASSWORD }}
35+
- name: Show Response
36+
run: echo ${{ steps.myRequest.outputs.response }}

0 commit comments

Comments
 (0)