Skip to content

Commit 83e7db4

Browse files
authored
Adding app-name-matcher to Action params (#57)
* Adding app-name-matcher to Action params * Expanding README example * Splitting Actions * Re-adding build Action * Marking generated code * Adding .env example
1 parent 89e8630 commit 83e7db4

File tree

9 files changed

+481
-350
lines changed

9 files changed

+481
-350
lines changed

.env.example

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Do not commit your actual .env file to Git! This may contain secrets or other
2+
# private information.
3+
4+
# Enable/disable step debug logging (default: `false`). For local debugging, it
5+
# may be useful to set it to `true`.
6+
ACTIONS_STEP_DEBUG=true
7+
8+
# GitHub Actions inputs should follow `INPUT_<name>` format (case-sensitive).
9+
# Hyphens should not be converted to underscores!
10+
# INPUT_MILLISECONDS=2400
11+
12+
# GitHub Actions default environment variables. These are set for every run of a
13+
# workflow and can be used in your actions. Setting the value here will override
14+
# any value set by the local-action tool.
15+
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
16+
17+
# CI="true"
18+
# GITHUB_ACTION=""
19+
# GITHUB_ACTION_PATH=""
20+
# GITHUB_ACTION_REPOSITORY=""
21+
# GITHUB_ACTIONS=""
22+
# GITHUB_ACTOR=""
23+
# GITHUB_ACTOR_ID=""
24+
# GITHUB_API_URL=""
25+
# GITHUB_BASE_REF=""
26+
# GITHUB_ENV=""
27+
# GITHUB_EVENT_NAME=""
28+
# GITHUB_EVENT_PATH=""
29+
# GITHUB_GRAPHQL_URL=""
30+
# GITHUB_HEAD_REF=""
31+
# GITHUB_JOB=""
32+
# GITHUB_OUTPUT=""
33+
# GITHUB_PATH=""
34+
# GITHUB_REF=""
35+
# GITHUB_REF_NAME=""
36+
# GITHUB_REF_PROTECTED=""
37+
# GITHUB_REF_TYPE=""
38+
# GITHUB_REPOSITORY=""
39+
# GITHUB_REPOSITORY_ID=""
40+
# GITHUB_REPOSITORY_OWNER=""
41+
# GITHUB_REPOSITORY_OWNER_ID=""
42+
# GITHUB_RETENTION_DAYS=""
43+
# GITHUB_RUN_ATTEMPT=""
44+
# GITHUB_RUN_ID=""
45+
# GITHUB_RUN_NUMBER=""
46+
# GITHUB_SERVER_URL=""
47+
# GITHUB_SHA=""
48+
# GITHUB_STEP_SUMMARY=""
49+
# GITHUB_TRIGGERING_ACTOR=""
50+
# GITHUB_WORKFLOW=""
51+
# GITHUB_WORKFLOW_REF=""
52+
# GITHUB_WORKFLOW_SHA=""
53+
# GITHUB_WORKSPACE=""
54+
# RUNNER_ARCH=""
55+
# RUNNER_DEBUG=""
56+
# RUNNER_NAME=""
57+
# RUNNER_OS=""
58+
# RUNNER_TEMP=""
59+
# RUNNER_TOOL_CACHE=""

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto eol=lf
2+
3+
dist/** -diff linguist-generated=true

.github/workflows/build.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: "build"
2+
on: # rebuild any PRs and main branch changes
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
- 'releases/*'
8+
9+
jobs:
10+
build: # make sure build/ci work properly
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- run: |
15+
npm install
16+
npm run all

.github/workflows/test.yml

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "build-test"
1+
name: "test"
22
on: # rebuild any PRs and main branch changes
33
pull_request:
44
push:
@@ -7,14 +7,6 @@ on: # rebuild any PRs and main branch changes
77
- 'releases/*'
88

99
jobs:
10-
build: # make sure build/ci work properly
11-
runs-on: ubuntu-latest
12-
steps:
13-
- uses: actions/checkout@v4
14-
- run: |
15-
npm install
16-
npm run all
17-
1810
test: # make sure the action works on a clean machine without building
1911
runs-on: ubuntu-latest
2012
steps:

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ jobs:
3030
argocd-token: ${{ secrets.ARGOCD_TOKEN }}
3131
github-token: ${{ secrets.GITHUB_TOKEN }}
3232
argocd-version: v1.6.1
33-
argocd-extra-cli-args: --grpc-web
33+
argocd-extra-cli-args: --grpc-web # optional
34+
app-name-matcher: "/^myapp-/" # optional
35+
plaintext: true # optional
36+
environment: myenv # optional
3437
```
3538
3639
## How it works

__tests__/main.test.ts

+33-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,44 @@
11
import os from 'os';
2+
import { run, filterAppsByName, type App } from '../src/main';
23

3-
describe('main', () => {
4+
describe('Action', () => {
45
// shows how the runner will run a javascript action with env / stdout protocol
5-
test('test runs', async () => {
6+
test('runs', async () => {
67
process.env['RUNNER_TEMP'] = os.tmpdir();
78
process.env['GITHUB_REPOSITORY'] = 'quizlet/cd-infra';
89
process.env['INPUT_GITHUB-TOKEN'] = '500';
910
process.env['INPUT_ARGOCD-VERSION'] = 'v1.6.1';
1011
process.env['INPUT_ARGOCD-SERVER-URL'] = 'argocd.qzlt.io';
1112
process.env['INPUT_ARGOCD-TOKEN'] = 'foo';
12-
expect(import('../src/main')).resolves.toBeTruthy();
13+
expect(run()).rejects.toThrow();
14+
});
15+
16+
describe('matches app names', () => {
17+
const makeApp = (name: string) => ({ metadata: { name } }) as App;
18+
19+
test('allows all apps when matcher is empty', () => {
20+
expect(filterAppsByName([makeApp('foobar'), makeApp('bazqux')], '')).toEqual([
21+
makeApp('foobar'),
22+
makeApp('bazqux')
23+
]);
24+
});
25+
26+
test('allows only apps when matcher is provided', () => {
27+
expect(filterAppsByName([makeApp('foobar'), makeApp('bazqux')], 'foobar')).toEqual([
28+
makeApp('foobar')
29+
]);
30+
});
31+
32+
test('treats matcher as regex when it is delimited by slashes', () => {
33+
expect(filterAppsByName([makeApp('foobar'), makeApp('bazqux')], '/bar$/')).toEqual([
34+
makeApp('foobar')
35+
]);
36+
});
37+
38+
test('with negative lookahead in regex', () => {
39+
expect(filterAppsByName([makeApp('foobar'), makeApp('bazqux')], '/^(?!foobar$).*$/')).toEqual(
40+
[makeApp('bazqux')]
41+
);
42+
});
1343
});
1444
});

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ inputs:
2828
description: Name of env to use in the diff title posted to the PR
2929
default: legacy
3030
required: false
31+
app-name-matcher:
32+
description: Comma-separated list or '/'-delimited regex of app names to include in diff output
33+
default: ""
34+
required: false
3135
runs:
3236
using: 'node20'
3337
main: 'dist/index.js'

0 commit comments

Comments
 (0)