Skip to content

Commit

Permalink
feat: deployment updates (#52)
Browse files Browse the repository at this point in the history
* adding misc cleanup: checks for v1 and next tags, prettier/eslint autofix, integration tests as part of PR, updated fixutres, switch repo to use https instead of git (this may need to be configurable rather than assumed)
* fix linting rules
* add debugging support when action fails
  • Loading branch information
ejhayes committed Feb 24, 2023
1 parent f300270 commit e961c4e
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 21 deletions.
18 changes: 18 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
INPUT_ACTION=upsert
INPUT_ACCESSTOKEN=
INPUT_BASEURL=https://MY_SERVER_BASE_URL
INPUT_NAME=test
INPUT_NAMESPACE=default
INPUT_PROJECT=default
INPUT_CLUSTERNAME=in-cluster
INPUT_PATH=fixtures
INPUT_VALUESFILE=fixtures/values.yml
INPUT_DRYRUN=false
GITHUB_REF=refs/branches/develop
GITHUB_SHA=1234567
GITHUB_SERVER_URL=https://github.com
GITHUB_REPOSITORY=Owner/Repo
GITHUB_STEP_SUMMARY=/dev/stdout
INPUT_TOKENS={"TAG": "latest"}
INPUT_LABELS={}
INPUT_INFO={}
9 changes: 9 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# What changed

Describe your changes here.

<!--
## Release Notes
If you want to add additional information to the release notes include them here. Otherwise omit this section.
-->
54 changes: 45 additions & 9 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,56 @@ jobs:
pr:
runs-on: ubuntu-latest
steps:
- if: runner.debug == 1
run: |
set
cat $GITHUB_EVENT_PATH
- uses: actions/checkout@v3
- name: Prepare repository
run: git fetch --tags
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: actions/cache@v3
with:
path: ./node_modules
key: modules-${{ hashFiles('package-lock.json') }}
- env:
- run: npm ci
- uses: wearerequired/lint-action@v2
with:
eslint: true
eslint_extensions: ts
prettier: true
prettier_extensions: ts,json,js,yml
# do not autofix for bots (unlikely this scenario will be encountered)
auto_fix: ${{ env.BOT != '1' && true || false }}
commit_message: 'chore(lint): Fix code style issues with ${linter}'
github_token: ${{ secrets.GITHUB_TOKEN }} # NOTE: Important: Make sure to exclude the .github directory in your ESLint and Prettier configs as the default GITHUB_TOKEN cannot be used to update workflow files due to the missing workflow permission
git_email: 'github-action@users.noreply.github.com'
eslint_args: '--max-warnings 0'
- run: npm run ci:build
- name: Test Invocation
env:
INPUT_ACCESSTOKEN: dummyToken
INPUT_ACTION: upsert
INPUT_BASEURL: http://localhost
INPUT_CLUSTERNAME: in-cluster
INPUT_DRYRUN: true
INPUT_INFO: '{}'
INPUT_LABELS: '{}'
INPUT_NAME: test
INPUT_NAMESPACE: default
INPUT_PATH: fixtures
INPUT_PROJECT: default
INPUT_TOKENS: '{"TAG": "latest"}'
INPUT_VALUESFILE: fixtures/values.yaml
run: node dist/index.js
- name: Version Dry Run
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm ci
npm run ci:build
npx auto shipit -d
run: npx auto shipit -d

debug:
if: ${{ failure() }}
needs: [pr]
runs-on: ubuntu-latest
steps:
- run: |
set
cat $GITHUB_EVENT_PATH
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
token: ${{ secrets.GH_TOKEN }}
- name: Prepare repository
run: git fetch --unshallow --tags
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: actions/cache@v3
with:
path: ./node_modules
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/tag_next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ jobs:
namespace: default
path: fixtures
project: default
valuesFile: fixtures/values.yml
valuesFile: fixtures/values.yaml
tokens: |
MYSECRET: somestring-${{ secrets.GITHUB_TOKEN }}
OTHERTOKEN: theOtherValue
TAG: latest
annotations: |
myannotation: "true"
labels: |
Expand All @@ -31,4 +30,3 @@ jobs:
info: |
rev: ${{ github.ref }}
sha: ${{ github.sha }}
32 changes: 32 additions & 0 deletions .github/workflows/tag_v1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
push:
branches:
- releases/v1

jobs:
verify_action_works:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ejhayes/action-argocd-deploy@releases/v1
with:
dryRun: true
clientId: username
clientSecret: password
clusterName: 'default'
baseUrl: https://example.com
name: my-service
namespace: default
path: fixtures
project: default
valuesFile: fixtures/values.yaml
tokens: |
TAG: latest
annotations: |
myannotation: "true"
labels: |
group: group-a
env: prod
info: |
rev: ${{ github.ref }}
sha: ${{ github.sha }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
dist
node_modules
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ To use this in your projects:
### minimal example

Using [access token](https://argo-cd.readthedocs.io/en/latest/user-guide/commands/argocd_account_generate-token/):

```yaml
- uses: ejhayes/action-argocd-deploy@releases/v1
with:
Expand All @@ -38,6 +39,7 @@ Using [access token](https://argo-cd.readthedocs.io/en/latest/user-guide/command
```

Using username/password (or clientid/secret):

```yaml
- uses: ejhayes/action-argocd-deploy@releases/v1
with:
Expand Down Expand Up @@ -93,6 +95,7 @@ jobs:
```

Example `fixtures/values.yml` would contain:

```yaml
service:
someParam:
Expand Down
3 changes: 3 additions & 0 deletions fixtures/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apiVersion: v2
name: argo-cd
version: 1.0.0
6 changes: 6 additions & 0 deletions fixtures/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: rds-cluster-config
data:
myKey: { { .Values.my_config } }
1 change: 1 addition & 0 deletions fixtures/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
my_config: __TAG__
3 changes: 0 additions & 3 deletions fixtures/values.yml

This file was deleted.

60 changes: 60 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"format": "prettier --write .",
"lint": "eslint \"{src,test}/**/*.ts\"",
"package": "rimraf dist && ncc build --source-map",
"test": "npm run lint && npm run format"
"test": "dotenv ts-node src/index.ts"
},
"repository": {
"type": "git",
Expand All @@ -35,6 +35,7 @@
"@vercel/ncc": "^0.34.0",
"action-docs": "^1.0.4",
"auto": "^10.37.6",
"dotenv-cli": "^7.0.0",
"eslint": "^8.24.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
Expand Down
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,11 @@ function getInputs(): ActionArgs {
process.env.GITHUB_REF.replace(/refs\/[^\/]+\/([^\/]+).*/, '$1'),
gitSha: process.env.GITHUB_SHA,
gitWebUrl: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}`,
gitRepoUrl: `${process.env.GITHUB_SERVER_URL.replace(
/^https:/,
'git:',
)}/${process.env.GITHUB_REPOSITORY.replace(/(?<!\.git)$/, '.git')}`,
/**
* TODO: this can be either https or git depending on argocd setup. rather than
* making an assumption here this should be cleaned up to be configurable
*/
gitRepoUrl: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}`,
name: core.getInput(INPUTS.NAME, { required: true }),
namespace: core.getInput(INPUTS.NAMESPACE, { required: true }),
project: core.getInput(INPUTS.PROJECT, { required: true }),
Expand Down

0 comments on commit e961c4e

Please sign in to comment.