Skip to content
Closed
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
159 changes: 159 additions & 0 deletions .github/workflows/_ci_action_keyphrase_checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
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 the test to fail but it passed"
exit 1
fi
if [[ "${{ steps.test-direct-text.outputs.occurences }}" != "0" ]]; 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 the test to fail but it passed"
exit 1
fi
if [[ "${{ steps.test-text-file.outputs.occurences }}" != "1" ]]; then
echo "Expected 1 occurrences but found ${{ steps.test-text-file.outputs.occurences }}"
exit 1
fi


49 changes: 49 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Dependency directories
node_modules/
jspm_packages/

# Coverage directories used by tools like istanbul, jest
coverage/
.nyc_output/

# Environment files
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Debug logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
*.log

# OS specific files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Editor directories and files
.idea/
.vscode/*
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/settings.json
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.sublime-workspace

# Temporary files
*.tmp
*.temp
tmp/
temp/
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Keyphrase Checker Action",
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["-r", "ts-node/register"],
"program": "${workspaceFolder}/actions/keyphrase-checker/src/index.ts",
"cwd": "${workspaceFolder}/actions/keyphrase-checker",
"console": "integratedTerminal",
"env": {
"INPUT_TEXT-FILE": "README.md",
"INPUT_KEYPHRASE": "GitHub",
"INPUT_CASE-SENSITIVE": "true",
"INPUT_MINIMUM-OCCURENCES": 2,
"GITHUB_WORKSPACE": "${workspaceFolder}"
}
}
]
}
21 changes: 21 additions & 0 deletions actions/keyphrase-checker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Keyphrase Checker Action

A GitHub Action that checks for the occurrence of a specified keyphrase in a file or direct text input and fails if the number of occurrences is below a specified minimum. This action is especially useful for GitHub Skills exercises to verify that learners have added specific content to their files, issue comments or other text fields.

## Inputs

| Input | Description | Required | Default |
| -------------------- | ------------------------------------------------------------- | -------- | ------- |
| `text-file` | Path to the file to check (use either this or `text`) | No\* | N/A |
| `text` | Direct text content to check (use either this or `text-file`) | No\* | N/A |
| `keyphrase` | The keyphrase to search for | Yes | N/A |
| `minimum-occurences` | Minimum number of occurrences required | No | 1 |
| `case-sensitive` | Whether the search should be case-sensitive | No | false |

\*Note: Exactly one of `text-file` or `text` must be provided.

## Outputs

| Output | Description |
| ------------ | ------------------------------- |
| `occurences` | The number of occurrences found |
Loading
Loading