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

added whiskers for ci #17

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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@ac593985615ec2ede58e132d2e21d2b1cbd6127c
with:
clean: true
fetch-depth: 1

- name: node > setup
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c
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@ac593985615ec2ede58e132d2e21d2b1cbd6127c
with:
clean: true
fetch-depth: 1

- name: node > setup
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c
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@ac593985615ec2ede58e132d2e21d2b1cbd6127c
with:
clean: true
fetch-depth: 1
token: ${{ secrets.BOT_GITHUB_TOKEN }}
ref: ${{ inputs.branch }}

- name: node > setup
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c
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@ac593985615ec2ede58e132d2e21d2b1cbd6127c
with:
clean: true
fetch-depth: 1
token: ${{ secrets.BOT_GITHUB_TOKEN }}
ref: v${{ inputs.version }}

- name: node > setup
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c
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@ac593985615ec2ede58e132d2e21d2b1cbd6127c
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 { prefixEnumValues } 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 = prefixEnumValues(SecretKeys, 'secrets.');
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
Loading