feat: add keyphrase-checker GitHub Action #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Keyphrase Checker Action CI | |
on: | |
pull_request: | |
branches: | |
- main | |
paths: | |
- actions/keyphrase-checker/** | |
permissions: | |
contents: read | |
defaults: | |
run: | |
working-directory: actions/keyphrase-checker | |
shell: bash | |
jobs: | |
check-dist: | |
name: Check dist/ | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
id: checkout | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
id: setup-node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: npm | |
cache-dependency-path: actions/keyphrase-checker/package-lock.json | |
- name: Install Dependencies | |
run: npm ci | |
- name: Build dist/ Directory | |
run: npm run all | |
# This will fail the workflow if the `dist/` directory is different than | |
# expected. | |
- name: Compare Directories | |
id: diff | |
run: | | |
if [ ! -d dist/ ]; then | |
echo "Expected dist/ directory does not exist. See status below:" | |
ls -la ./ | |
exit 1 | |
fi | |
if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then | |
echo "Detected uncommitted changes after build. See status below:" | |
git diff --ignore-space-at-eol --text dist/ | |
exit 1 | |
fi | |
# If `dist/` was different than expected, upload the expected version as a | |
# workflow artifact. | |
- if: ${{ failure() && steps.diff.outcome == 'failure' }} | |
name: Upload Artifact | |
id: upload | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist | |
path: actions/keyphrase-checker/dist/ | |
run-ts-tests: | |
name: Run TS Tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
id: checkout | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
id: setup-node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: npm | |
cache-dependency-path: actions/keyphrase-checker/package-lock.json | |
- name: Install Dependencies | |
run: npm ci | |
- name: Test | |
run: npm run test | |
positive-tests: | |
name: Positive Action Tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Test direct text (not case-sensitive) | |
id: test-direct-text | |
uses: ./actions/keyphrase-checker | |
with: | |
text: "Hey @PrOfEssortocat, I'm finished with my task" | |
keyphrase: "@professortocat" | |
- name: Test text file (not case-sensitive) | |
id: test-text-file | |
uses: ./actions/keyphrase-checker | |
with: | |
text-file: ./actions/keyphrase-checker/__tests__/test-mixed-case.md | |
keyphrase: "github" | |
minimum-occurences: "3" | |
negative-tests: | |
name: Negative Action Tests | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Test direct text (case-sensitive) | |
id: test-direct-text | |
continue-on-error: true | |
uses: ./actions/keyphrase-checker | |
with: | |
text: "Hey @PrOfEssortocat, I'm finished with my task" | |
keyphrase: "@professortocat" | |
case-sensitive: true | |
- name: Check output for direct text test | |
run: | | |
if [[ "${{ steps.test-direct-text.outcome }}" != "failure" ]]; then | |
echo "Expected 0 occurrences but found ${{ steps.test-direct-text.outputs.occurences }}" | |
exit 1 | |
fi | |
- name: Test text file (case-sensitive) | |
id: test-text-file | |
continue-on-error: true | |
uses: ./actions/keyphrase-checker | |
with: | |
text-file: ./actions/keyphrase-checker/__tests__/test-mixed-case.md | |
keyphrase: "github" | |
minimum-occurences: "3" | |
case-sensitive: true | |
- name: Check output for text file test | |
run: | | |
if [[ "${{ steps.test-text-file.outcome }}" != "failure" ]]; then | |
echo "Expected 1 occurrences but found ${{ steps.test-text-file.outputs.occurences }}" | |
exit 1 | |
fi | |