Skip to content

Commit 7626ee4

Browse files
ci: add CI for keyphrase-checker action
1 parent f44aaa2 commit 7626ee4

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
name: Keyphrase Checker Action CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- actions/keyphrase-checker/**
9+
10+
permissions:
11+
contents: read
12+
13+
defaults:
14+
run:
15+
working-directory: actions/keyphrase-checker
16+
shell: bash
17+
18+
jobs:
19+
check-dist:
20+
name: Check dist/
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Checkout
25+
id: checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Setup Node.js
29+
id: setup-node
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: 20
33+
cache: npm
34+
cache-dependency-path: actions/keyphrase-checker/package-lock.json
35+
36+
- name: Install Dependencies
37+
run: npm ci
38+
39+
- name: Build dist/ Directory
40+
run: npm run all
41+
42+
# This will fail the workflow if the `dist/` directory is different than
43+
# expected.
44+
- name: Compare Directories
45+
id: diff
46+
run: |
47+
if [ ! -d dist/ ]; then
48+
echo "Expected dist/ directory does not exist. See status below:"
49+
ls -la ./
50+
exit 1
51+
fi
52+
if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then
53+
echo "Detected uncommitted changes after build. See status below:"
54+
git diff --ignore-space-at-eol --text dist/
55+
exit 1
56+
fi
57+
58+
# If `dist/` was different than expected, upload the expected version as a
59+
# workflow artifact.
60+
- if: ${{ failure() && steps.diff.outcome == 'failure' }}
61+
name: Upload Artifact
62+
id: upload
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: dist
66+
path: actions/keyphrase-checker/dist/
67+
68+
run-ts-tests:
69+
name: Run TS Tests
70+
runs-on: ubuntu-latest
71+
72+
steps:
73+
- name: Checkout
74+
id: checkout
75+
uses: actions/checkout@v4
76+
77+
- name: Setup Node.js
78+
id: setup-node
79+
uses: actions/setup-node@v4
80+
with:
81+
node-version: 20
82+
cache: npm
83+
cache-dependency-path: actions/keyphrase-checker/package-lock.json
84+
85+
- name: Install Dependencies
86+
run: npm ci
87+
88+
- name: Test
89+
run: npm run test
90+
91+
positive-tests:
92+
name: Positive Action Tests
93+
runs-on: ubuntu-latest
94+
steps:
95+
- name: Checkout
96+
uses: actions/checkout@v4
97+
98+
- name: Test direct text (not case-sensitive)
99+
id: test-direct-text
100+
uses: ./actions/keyphrase-checker
101+
with:
102+
text: "Hey @PrOfEssortocat, I'm finished with my task"
103+
keyphrase: "@professortocat"
104+
105+
- name: Test text file (not case-sensitive)
106+
id: test-text-file
107+
uses: ./actions/keyphrase-checker
108+
with:
109+
text-file: ./actions/keyphrase-checker/__tests__/test-mixed-case.md
110+
keyphrase: "github"
111+
minimum-occurences: "3"
112+
113+
negative-tests:
114+
name: Negative Action Tests
115+
runs-on: ubuntu-latest
116+
steps:
117+
- uses: actions/checkout@v4
118+
- name: Test direct text (case-sensitive)
119+
id: test-direct-text
120+
continue-on-error: true
121+
uses: ./actions/keyphrase-checker
122+
with:
123+
text: "Hey @PrOfEssortocat, I'm finished with my task"
124+
keyphrase: "@professortocat"
125+
case-sensitive: true
126+
127+
- name: Check output for direct text test
128+
run: |
129+
if [[ "${{ steps.test-direct-text.outcome }}" != "failure" ]]; then
130+
echo "Expected 0 occurrences but found ${{ steps.test-direct-text.outputs.occurences }}"
131+
exit 1
132+
fi
133+
134+
- name: Test text file (case-sensitive)
135+
id: test-text-file
136+
continue-on-error: true
137+
uses: ./actions/keyphrase-checker
138+
with:
139+
text-file: ./actions/keyphrase-checker/__tests__/test-mixed-case.md
140+
keyphrase: "github"
141+
minimum-occurences: "3"
142+
case-sensitive: true
143+
144+
- name: Check output for text file test
145+
run: |
146+
if [[ "${{ steps.test-text-file.outputs.outcome }}" != "failure" ]]; then
147+
echo "Expected 1 occurrences but found ${{ steps.test-text-file.outputs.occurences }}"
148+
exit 1
149+
fi
150+
151+

0 commit comments

Comments
 (0)