Skip to content
Open
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
122 changes: 122 additions & 0 deletions .github/workflows/test-pre-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Test pre-job

on:
workflow_dispatch:
pull_request:
push:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions: {}

jobs:
pre-job:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
should_run: ${{ steps.check.outputs.should_run }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false

- name: Check what should run
id: check
uses: ./actions/pre-job
with:
github-token: ${{ github.token }}
filters: |
pre_job:
- 'actions/pre-job/**'
force-filters: |
- '.github/workflows/test-pre-job.yml'

tests:
needs: pre-job
if: ${{ fromJSON(needs.pre-job.outputs.should_run).pre_job == true }}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false

- name: Self-detection (per-rule path matching)
id: self-detection
if: github.event_name != 'workflow_dispatch'
uses: ./actions/pre-job
with:
github-token: ${{ github.token }}
filters: |
self:
- 'actions/pre-job/**'
other:
- 'definitely-does-not-exist/**'
- name: Assert self-detection
if: github.event_name != 'workflow_dispatch'
env:
RESULTS: ${{ steps.self-detection.outputs.should_run }}
run: |
echo "got: $RESULTS"
echo "$RESULTS" | jq -e '.self == true' > /dev/null || { echo "::error::self filter should be true"; exit 1; }
echo "$RESULTS" | jq -e '.other == false' > /dev/null || { echo "::error::other filter should be false"; exit 1; }

- name: Force-events short-circuit (workflow_dispatch only)
id: force-event
if: github.event_name == 'workflow_dispatch'
uses: ./actions/pre-job
with:
github-token: ${{ github.token }}
filters: |
anything:
- 'never-matches-anything/**'
force-events: 'workflow_dispatch'
- name: Assert force-events
if: github.event_name == 'workflow_dispatch'
env:
RESULTS: ${{ steps.force-event.outputs.should_run }}
run: |
echo "got: $RESULTS"
echo "$RESULTS" | jq -e '.anything == true' > /dev/null || { echo "::error::force-events should have triggered"; exit 1; }

- name: Custom force input
id: force-input
uses: ./actions/pre-job
with:
github-token: ${{ github.token }}
filters: |
anything:
- 'never-matches-anything/**'
force: 'true'
- name: Assert force input
env:
RESULTS: ${{ steps.force-input.outputs.should_run }}
run: |
echo "got: $RESULTS"
echo "$RESULTS" | jq -e '.anything == true' > /dev/null || { echo "::error::force input should have triggered"; exit 1; }

- name: Object-form filter (paths/paths-ignore/status)
id: object-form
if: github.event_name != 'workflow_dispatch'
uses: ./actions/pre-job
with:
github-token: ${{ github.token }}
filters: |
object:
paths: ['actions/pre-job/**']
paths-ignore: ['actions/pre-job/this-path-never-exists/**']
status: [added, modified, deleted, renamed]
- name: Assert object-form
if: github.event_name != 'workflow_dispatch'
env:
RESULTS: ${{ steps.object-form.outputs.should_run }}
run: |
echo "got: $RESULTS"
echo "$RESULTS" | jq -e '.object == true' > /dev/null || { echo "::error::object-form filter should be true"; exit 1; }
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,4 @@ terragrunt-debug.tfvars.json

scripts/node_modules/
scripts/dist/
actions/pre-job/node_modules/
4 changes: 4 additions & 0 deletions actions/pre-job/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
node_modules/
package-lock.json
CHANGELOG.md
5 changes: 5 additions & 0 deletions actions/pre-job/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120
}
Loading
Loading