Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding app-name-matcher to Action params #57

Merged
merged 6 commits into from
Dec 6, 2024
Merged
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
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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled into separate CI step so it can pass and be required by GitHub Branch Protection Rules

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
Loading