Skip to content

Commit

Permalink
Merge pull request #17 from useparagon/feat/add-whiskers
Browse files Browse the repository at this point in the history
added whiskers for ci
  • Loading branch information
jromero-pg authored Jun 24, 2024
2 parents fdc9a44 + 6da189e commit ede82a9
Show file tree
Hide file tree
Showing 13 changed files with 884 additions and 10 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
## ---------------------------------------------------
## |\---/|
## | ,_, | !! DO NOT MODIFY !!
## \_`_/-..----. file managed by `whiskers`
## ___/ ` ' ,""+ \
## (__...' __\ |`.___.';
## (_,...'(_,.`__)/'.....+
## ---------------------------------------------------

name: build

on:
pull_request: {}
push:
branches:
- master

jobs:
build:
name: build
runs-on: ubuntu-latest
steps:

- name: git > checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
with:
clean: true
fetch-depth: 1

- name: node > setup
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8
with:
node-version-file: .nvmrc
cache: yarn

- name: yarn > install
run: yarn install --frozen-lockfile

- name: yarn > build
env:
NODE_ENV: production
run: yarn build

- name: ci > upload artifacts
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32
with:
name: dist
path: dist/
if-no-files-found: error
lint:
name: lint
runs-on: ubuntu-latest
steps:

- name: git > checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
with:
clean: true
fetch-depth: 1

- name: node > setup
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8
with:
node-version-file: .nvmrc
cache: yarn

- name: yarn > install
run: yarn install --frozen-lockfile

- name: yarn > lint
run: yarn lint
verify_workflow:
name: verify workflow
runs-on: ubuntu-latest
if: always()
needs:
- build
- lint
steps:

- name: verify workflow success
if: always()
run: |-
# resolve statuses
BUILD_AGGREGATE=(${{ needs['build'].result }})
BUILD=unknown
BUILD=$(if [[ " ${BUILD_AGGREGATE[@]} " == *"success"* ]]; then echo "success"; else echo "$BUILD"; fi)
BUILD=$(if [[ " ${BUILD_AGGREGATE[@]} " == *"skipped"* ]]; then echo "skipped"; else echo "$BUILD"; fi)
BUILD=$(if [[ " ${BUILD_AGGREGATE[@]} " == *"cancelled"* ]]; then echo "cancelled"; else echo "$BUILD"; fi)
BUILD=$(if [[ " ${BUILD_AGGREGATE[@]} " == *"failure"* ]]; then echo "failure"; else echo "$BUILD"; fi)
LINT_AGGREGATE=(${{ needs['lint'].result }})
LINT=unknown
LINT=$(if [[ " ${LINT_AGGREGATE[@]} " == *"success"* ]]; then echo "success"; else echo "$LINT"; fi)
LINT=$(if [[ " ${LINT_AGGREGATE[@]} " == *"skipped"* ]]; then echo "skipped"; else echo "$LINT"; fi)
LINT=$(if [[ " ${LINT_AGGREGATE[@]} " == *"cancelled"* ]]; then echo "cancelled"; else echo "$LINT"; fi)
LINT=$(if [[ " ${LINT_AGGREGATE[@]} " == *"failure"* ]]; then echo "failure"; else echo "$LINT"; fi)
# echo the results of each job
echo "BUILD: $BUILD"
echo "LINT: $LINT"
# assert success
if [[ "$BUILD" != "success" ]]; then exit 1; fi
if [[ "$LINT" != "success" ]]; then exit 1; fi
106 changes: 106 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
## ---------------------------------------------------
## |\---/|
## | ,_, | !! DO NOT MODIFY !!
## \_`_/-..----. file managed by `whiskers`
## ___/ ` ' ,""+ \
## (__...' __\ |`.___.';
## (_,...'(_,.`__)/'.....+
## ---------------------------------------------------

name: publish
run-name: publish v${{ inputs.version }}

on:
workflow_dispatch:
inputs:
branch:
description: The branch of the build. Used to find artifacts and tag.
required: true
release_type:
description: The type of release.
required: true
type: choice
options:
- experimental
- stable
default: experimental
version:
description: "The version of this release. Omit 'v' prefix. Example: '1.0.1-experimental.1'."
required: true

jobs:
version_bump:
name: version bump
runs-on: ubuntu-latest
timeout-minutes: 5
steps:

- name: git > checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
with:
clean: true
fetch-depth: 1
token: ${{ secrets.BOT_GITHUB_TOKEN }}
ref: ${{ inputs.branch }}

- name: node > setup
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8
with:
node-version-file: .nvmrc
cache: yarn

- name: yarn > install
run: yarn install --frozen-lockfile

- name: yarn > bump version
run: yarn run release:version:bump ${{ inputs.version }}

- name: git > commit version bump
uses: EndBug/add-and-commit@1bad3abcf0d6ec49a5857d124b0bfb52dc7bb081
with:
default_author: github_actions
message: bump version to ${{ inputs.version }}
push: true
tag: v${{ inputs.version }}
publish:
name: publish
runs-on: ubuntu-latest
needs:
- version_bump
steps:

- name: git > checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
with:
clean: true
fetch-depth: 1
token: ${{ secrets.BOT_GITHUB_TOKEN }}
ref: v${{ inputs.version }}

- name: node > setup
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8
with:
node-version-file: .nvmrc
cache: yarn

- name: yarn > install
run: yarn install --frozen-lockfile

- name: ci > download artifacts
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e
with:
workflow: build.yaml
workflow_conclusion: success
branch: ${{ inputs.branch }}

- name: yarn > publish (experimental)
if: inputs.release_type == 'experimental'
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: yarn run release:publish:experimental

- name: yarn > publish (stable)
if: inputs.release_type == 'stable'
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: yarn run release:publish:stable
36 changes: 36 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## ---------------------------------------------------
## |\---/|
## | ,_, | !! DO NOT MODIFY !!
## \_`_/-..----. file managed by `whiskers`
## ___/ ` ' ,""+ \
## (__...' __\ |`.___.';
## (_,...'(_,.`__)/'.....+
## ---------------------------------------------------

name: release

on:
push:
tags:
- v*.*.*

jobs:
release:
name: release
runs-on: ubuntu-latest
timeout-minutes: 10
steps:

- name: git > checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
with:
clean: true
fetch-depth: 1
token: ${{ secrets.BOT_GITHUB_TOKEN }}

- name: release > create github release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844
with:
token: ${{ secrets.BOT_GITHUB_TOKEN }}
generate_release_notes: true
prerelease: ${{ contains(github.ref, 'experimental') }}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.17.1
23 changes: 23 additions & 0 deletions .whiskers/steps/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { CheckoutParams, GitCheckoutWorkflowStep } from '@useparagon/whiskers-cattery-git';
import { SetupNodeWorkflowStep } from '@useparagon/whiskers-cattery-node';
import { GithubActionWorkflowStep, ShellStepConfig } from '@useparagon/whiskers-core';

export function setupSteps(params: CheckoutParams = {}): GithubActionWorkflowStep<any>[] {
return [
new GitCheckoutWorkflowStep({
name: 'git > checkout',
with: params,
}),
new SetupNodeWorkflowStep({
name: 'node > setup',
with: {
'node-version-file': '.nvmrc',
cache: 'yarn',
},
}),
new GithubActionWorkflowStep<ShellStepConfig>({
name: 'yarn > install',
run: 'yarn install --frozen-lockfile',
}),
];
}
4 changes: 4 additions & 0 deletions .whiskers/types/releases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum ReleaseTypes {
experimental = 'experimental',
stable = 'stable',
}
16 changes: 16 additions & 0 deletions .whiskers/types/secrets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { prefixSuffixEnumValues } from '@useparagon/whiskers-core';

export enum SecretKeys {
/**
* Personal access token for the GitHub bot to use for interactions with
* GitHub.
*/
BOT_GITHUB_TOKEN = 'BOT_GITHUB_TOKEN',

/**
* npm auth token for the npm registry.
*/
NPM_TOKEN = 'NPM_TOKEN',
}

export const Secrets = prefixSuffixEnumValues('secrets.', SecretKeys, '');
63 changes: 63 additions & 0 deletions .whiskers/workflows/build.workflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {
GithubActionWorkflow,
GithubActionWorkflowJob,
GithubActionWorkflowStep,
ActionsStepConfig,
ShellStepConfig,
} from '@useparagon/whiskers-core';
import { VerifyWorkflowSuccessGithubActionWorkflowJob } from '@useparagon/whiskers-cattery-github';

import { setupSteps } from '../steps/setup';

const JOB_ID_BUILD = 'build';
const JOB_ID_LINT = 'lint';

export default new GithubActionWorkflow({
name: 'build',
on: {
pull_request: {},
push: {
branches: ['master'],
},
},
jobs: [
new GithubActionWorkflowJob({
id: JOB_ID_BUILD,
name: 'build',
steps: [
...setupSteps(),
new GithubActionWorkflowStep<ShellStepConfig>({
name: 'yarn > build',
run: 'yarn build',
env: {
NODE_ENV: 'production',
},
}),
new GithubActionWorkflowStep<ActionsStepConfig<any>>({
name: 'ci > upload artifacts',
uses: 'actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32', // v3.1.3
with: {
name: 'dist',
path: 'dist/',
'if-no-files-found': 'error',
},
}),
],
}),
new GithubActionWorkflowJob({
id: JOB_ID_LINT,
name: 'lint',
steps: [
...setupSteps(),
new GithubActionWorkflowStep({
name: 'yarn > lint',
run: 'yarn lint',
}),
],
}),
new VerifyWorkflowSuccessGithubActionWorkflowJob({
BUILD: JOB_ID_BUILD,
LINT: JOB_ID_LINT,
}),
],
});
Loading

0 comments on commit ede82a9

Please sign in to comment.