Skip to content

Commit

Permalink
Adding app-name-matcher to Action params (#57)
Browse files Browse the repository at this point in the history
* Adding app-name-matcher to Action params

* Expanding README example

* Splitting Actions

* Re-adding build Action

* Marking generated code

* Adding .env example
  • Loading branch information
karoun authored Dec 6, 2024
1 parent 89e8630 commit 83e7db4
Show file tree
Hide file tree
Showing 9 changed files with 481 additions and 350 deletions.
59 changes: 59 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Do not commit your actual .env file to Git! This may contain secrets or other
# private information.

# Enable/disable step debug logging (default: `false`). For local debugging, it
# may be useful to set it to `true`.
ACTIONS_STEP_DEBUG=true

# GitHub Actions inputs should follow `INPUT_<name>` format (case-sensitive).
# Hyphens should not be converted to underscores!
# INPUT_MILLISECONDS=2400

# GitHub Actions default environment variables. These are set for every run of a
# workflow and can be used in your actions. Setting the value here will override
# any value set by the local-action tool.
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables

# CI="true"
# GITHUB_ACTION=""
# GITHUB_ACTION_PATH=""
# GITHUB_ACTION_REPOSITORY=""
# GITHUB_ACTIONS=""
# GITHUB_ACTOR=""
# GITHUB_ACTOR_ID=""
# GITHUB_API_URL=""
# GITHUB_BASE_REF=""
# GITHUB_ENV=""
# GITHUB_EVENT_NAME=""
# GITHUB_EVENT_PATH=""
# GITHUB_GRAPHQL_URL=""
# GITHUB_HEAD_REF=""
# GITHUB_JOB=""
# GITHUB_OUTPUT=""
# GITHUB_PATH=""
# GITHUB_REF=""
# GITHUB_REF_NAME=""
# GITHUB_REF_PROTECTED=""
# GITHUB_REF_TYPE=""
# GITHUB_REPOSITORY=""
# GITHUB_REPOSITORY_ID=""
# GITHUB_REPOSITORY_OWNER=""
# GITHUB_REPOSITORY_OWNER_ID=""
# GITHUB_RETENTION_DAYS=""
# GITHUB_RUN_ATTEMPT=""
# GITHUB_RUN_ID=""
# GITHUB_RUN_NUMBER=""
# GITHUB_SERVER_URL=""
# GITHUB_SHA=""
# GITHUB_STEP_SUMMARY=""
# GITHUB_TRIGGERING_ACTOR=""
# GITHUB_WORKFLOW=""
# GITHUB_WORKFLOW_REF=""
# GITHUB_WORKFLOW_SHA=""
# GITHUB_WORKSPACE=""
# RUNNER_ARCH=""
# RUNNER_DEBUG=""
# RUNNER_NAME=""
# RUNNER_OS=""
# RUNNER_TEMP=""
# RUNNER_TOOL_CACHE=""
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto eol=lf

dist/** -diff linguist-generated=true
16 changes: 16 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "build"
on: # rebuild any PRs and main branch changes
pull_request:
push:
branches:
- master
- 'releases/*'

jobs:
build: # make sure build/ci work properly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
npm install
npm run all
10 changes: 1 addition & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "build-test"
name: "test"
on: # rebuild any PRs and main branch changes
pull_request:
push:
Expand All @@ -7,14 +7,6 @@ on: # rebuild any PRs and main branch changes
- 'releases/*'

jobs:
build: # make sure build/ci work properly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
npm install
npm run all
test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ jobs:
argocd-token: ${{ secrets.ARGOCD_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
argocd-version: v1.6.1
argocd-extra-cli-args: --grpc-web
argocd-extra-cli-args: --grpc-web # optional
app-name-matcher: "/^myapp-/" # optional
plaintext: true # optional
environment: myenv # optional
```
## How it works
Expand Down
36 changes: 33 additions & 3 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
import os from 'os';
import { run, filterAppsByName, type App } from '../src/main';

describe('main', () => {
describe('Action', () => {
// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', async () => {
test('runs', async () => {
process.env['RUNNER_TEMP'] = os.tmpdir();
process.env['GITHUB_REPOSITORY'] = 'quizlet/cd-infra';
process.env['INPUT_GITHUB-TOKEN'] = '500';
process.env['INPUT_ARGOCD-VERSION'] = 'v1.6.1';
process.env['INPUT_ARGOCD-SERVER-URL'] = 'argocd.qzlt.io';
process.env['INPUT_ARGOCD-TOKEN'] = 'foo';
expect(import('../src/main')).resolves.toBeTruthy();
expect(run()).rejects.toThrow();
});

describe('matches app names', () => {
const makeApp = (name: string) => ({ metadata: { name } }) as App;

test('allows all apps when matcher is empty', () => {
expect(filterAppsByName([makeApp('foobar'), makeApp('bazqux')], '')).toEqual([
makeApp('foobar'),
makeApp('bazqux')
]);
});

test('allows only apps when matcher is provided', () => {
expect(filterAppsByName([makeApp('foobar'), makeApp('bazqux')], 'foobar')).toEqual([
makeApp('foobar')
]);
});

test('treats matcher as regex when it is delimited by slashes', () => {
expect(filterAppsByName([makeApp('foobar'), makeApp('bazqux')], '/bar$/')).toEqual([
makeApp('foobar')
]);
});

test('with negative lookahead in regex', () => {
expect(filterAppsByName([makeApp('foobar'), makeApp('bazqux')], '/^(?!foobar$).*$/')).toEqual(
[makeApp('bazqux')]
);
});
});
});
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ inputs:
description: Name of env to use in the diff title posted to the PR
default: legacy
required: false
app-name-matcher:
description: Comma-separated list or '/'-delimited regex of app names to include in diff output
default: ""
required: false
runs:
using: 'node20'
main: 'dist/index.js'
Loading

0 comments on commit 83e7db4

Please sign in to comment.