Skip to content

Commit

Permalink
[Kittyhawk] Configure version w Projen (#132)
Browse files Browse the repository at this point in the history
* 🆕 Configure version w Projen

* 🎨 WIP: Address changes

* chore(release): 1.2.0

* 🎨 It works now

* 🎨 Clean-up

* 🎨 Same thing w Kraken

* 🎨 lint -_-

* 🎨 Bump version & reconfig
  • Loading branch information
joyliu-q authored Apr 8, 2022
1 parent d39f6a7 commit efd8251
Show file tree
Hide file tree
Showing 34 changed files with 636 additions and 552 deletions.
1 change: 1 addition & 0 deletions cdk/kittyhawk/.projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const project = new TypeScriptProject({
},
});

project.addFields({['version']: '1.1.3'});
project.prettier?.ignoreFile?.addPatterns('src/imports');
project.testTask.steps.forEach(step => {
if (step.exec) {
Expand Down
18 changes: 0 additions & 18 deletions cdk/kittyhawk/.versionrc.json

This file was deleted.

5 changes: 5 additions & 0 deletions cdk/kittyhawk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog

## 1.1.3 (2022-04-08)

* Upgrade dependencies and fix projen version configuration

## 1.1.2 (2022-04-03)
* Dependency updates
* Move cdk8s-cli from `devDependencies` to `dependencies`
Expand Down
1 change: 0 additions & 1 deletion cdk/kittyhawk/version.json

This file was deleted.

1 change: 1 addition & 0 deletions cdk/kraken/.projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const project = new TypeScriptProject({
...common.options,
});

project.addFields({['version']: '0.8.6'});
project.prettier?.ignoreFile?.addPatterns('src/imports');
project.testTask.steps.forEach(step => {
if (step.exec) {
Expand Down
4 changes: 4 additions & 0 deletions cdk/kraken/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## X.Y.Z (UNRELEASED)

## 0.8.6 (2022-04-08)

* Upgrade dependencies and fix projen version configuration

## 0.8.5 (2022-04-05)

* CDK publish: fix conditional publish check
Expand Down
2 changes: 1 addition & 1 deletion cdk/kraken/package.json

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

20 changes: 10 additions & 10 deletions cdk/kraken/src/auto-approve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Workflow, Stack, WorkflowProps, Job } from 'cdkactions';
import { Construct } from 'constructs';
import { Workflow, Stack, WorkflowProps, Job } from "cdkactions";
import { Construct } from "constructs";

/**
* Auto-approve PRs opened by dependabot. Used to fulfil requirements
Expand All @@ -12,21 +12,21 @@ export class AutoApproveStack extends Stack {
* @param overrides Optional overrides for the stack.
*/
public constructor(scope: Construct, overrides?: Partial<WorkflowProps>) {
super(scope, 'autoapprove');
const workflow = new Workflow(this, 'autoapprove', {
name: 'Auto Approve dependabot PRs',
on: 'pullRequest',
super(scope, "autoapprove");
const workflow = new Workflow(this, "autoapprove", {
name: "Auto Approve dependabot PRs",
on: "pullRequest",
...overrides,
});

new Job(workflow, 'approve', {
runsOn: 'ubuntu-latest',
new Job(workflow, "approve", {
runsOn: "ubuntu-latest",
steps: [
{
uses: 'hmarr/auto-approve-action@v2.0.0',
uses: "hmarr/auto-approve-action@v2.0.0",
if: "github.actor == 'dependabot[bot]'",
with: {
'github-token': '${{ secrets.BOT_GITHUB_PAT }}',
"github-token": "${{ secrets.BOT_GITHUB_PAT }}",
},
},
],
Expand Down
127 changes: 67 additions & 60 deletions cdk/kraken/src/cdk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CheckoutJob, Workflow, Stack, WorkflowProps } from 'cdkactions';
import { Construct } from 'constructs';
import dedent from 'ts-dedent';
import { CheckoutJob, Workflow, Stack, WorkflowProps } from "cdkactions";
import { Construct } from "constructs";
import dedent from "ts-dedent";

/**
* Optional props to configure the CDK publish stack.
Expand Down Expand Up @@ -30,11 +30,16 @@ export class CDKPublishStack extends Stack {
* @param config Optional configuration for the cdk publish stack.
* @param overrides Optional overrides for the stack.
*/
public constructor(scope: Construct, id: string, config?: CDKPublishStackProps, overrides?: Partial<WorkflowProps>) {
public constructor(
scope: Construct,
id: string,
config?: CDKPublishStackProps,
overrides?: Partial<WorkflowProps>
) {
// Build config
const fullConfig: Required<CDKPublishStackProps> = {
defaultBranch: 'master',
nodeVersion: '14',
defaultBranch: "master",
nodeVersion: "14",
...config,
};
const path = `cdk/${id}`;
Expand All @@ -48,78 +53,80 @@ export class CDKPublishStack extends Stack {
},
...overrides,
});
new CheckoutJob(workflow, 'publish', {
runsOn: 'ubuntu-latest',
steps: [{
name: 'Cache',
uses: 'actions/cache@v2',
with: {
path: '**/node_modules',
key: `v0-\${{ hashFiles('${path}/yarn.lock') }}`,
new CheckoutJob(workflow, "publish", {
runsOn: "ubuntu-latest",
steps: [
{
name: "Cache",
uses: "actions/cache@v2",
with: {
path: "**/node_modules",
key: `v0-\${{ hashFiles('${path}/yarn.lock') }}`,
},
},
},
{
name: 'Install Dependencies',
run: dedent`cd ${path}
{
name: "Install Dependencies",
run: dedent`cd ${path}
yarn install --frozen-lockfile`,
},
{
name: 'Test',
run: dedent`cd ${path}
},
{
name: "Test",
run: dedent`cd ${path}
yarn test`,
},
{
name: 'Upload Code Coverage',
run: dedent`ROOT=$(pwd)
},
{
name: "Upload Code Coverage",
run: dedent`ROOT=$(pwd)
cd ${path}
yarn run codecov -p $ROOT -F ${id}`,
},
{
name: 'Install jq',
run: dedent`
},
{
name: "Install jq",
run: dedent`
curl -sSLo /usr/bin/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
chmod +x /usr/bin/jq`,
},
{
name: 'Check if version is already published to npm',
id: 'version_check',
run: dedent`cd ${path}
},
{
name: "Check if version is already published to npm",
id: "version_check",
run: dedent`cd ${path}
PACKAGE=\$(node -p "require('./package.json').name")
VERSION=\$(node -p "require('./package.json').version")
NEW_VERSION=\$(yarn info $PACKAGE versions --json | jq ".data | any(. == \\"$VERSION\\") | not")
echo "::set-output name=NEW_VERSION::$NEW_VERSION"`,
},
{
name: 'Publish to npm',
run: dedent`cd ${path}
},
{
name: "Publish to npm",
run: dedent`cd ${path}
yarn compile
yarn package
mv dist/js/*.tgz dist/js/${id}.tgz
yarn publish --non-interactive --access public dist/js/${id}.tgz`,
if: `github.ref == 'refs/heads/${fullConfig.defaultBranch}' && steps.version_check.outputs.NEW_VERSION == 'true'`,
env: {
NPM_AUTH_TOKEN: '${{ secrets.NPM_AUTH_TOKEN }}',
if: `github.ref == 'refs/heads/${fullConfig.defaultBranch}' && steps.version_check.outputs.NEW_VERSION == 'true'`,
env: {
NPM_AUTH_TOKEN: "${{ secrets.NPM_AUTH_TOKEN }}",
},
},
},
{
name: 'Build docs',
run: dedent`cd ${path}
{
name: "Build docs",
run: dedent`cd ${path}
yarn docgen`,
},
{
name: 'Publish docs',
if: `github.ref == 'refs/heads/${fullConfig.defaultBranch}'`,
uses: 'peaceiris/actions-gh-pages@v3',
with: {
personal_token: '${{ secrets.BOT_GITHUB_PAT }}',
external_repository: `pennlabs/${id}-docs`,
cname: `${id}.pennlabs.org`,
publish_branch: 'master',
publish_dir: `${path}/docs`,
user_name: 'github-actions',
user_email: 'github-actions[bot]@users.noreply.github.com',
},
}],
{
name: "Publish docs",
if: `github.ref == 'refs/heads/${fullConfig.defaultBranch}'`,
uses: "peaceiris/actions-gh-pages@v3",
with: {
personal_token: "${{ secrets.BOT_GITHUB_PAT }}",
external_repository: `pennlabs/${id}-docs`,
cname: `${id}.pennlabs.org`,
publish_branch: "master",
publish_dir: `${path}/docs`,
user_name: "github-actions",
user_email: "github-actions[bot]@users.noreply.github.com",
},
},
],
container: {
image: `node:${fullConfig.nodeVersion}`,
},
Expand Down
34 changes: 19 additions & 15 deletions cdk/kraken/src/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CheckoutJob, Workflow, JobProps } from 'cdkactions';
import dedent from 'ts-dedent';
import { CheckoutJob, Workflow, JobProps } from "cdkactions";
import dedent from "ts-dedent";

/**
* Optional props to configure the deploy job.
Expand Down Expand Up @@ -28,21 +28,25 @@ export class DeployJob extends CheckoutJob {
* @param config Optional configuration for the deploy job.
* @param overrides Optional overrides for the job.
*/
public constructor(scope: Workflow, config?: DeployJobProps, overrides?: Partial<JobProps>) {
public constructor(
scope: Workflow,
config?: DeployJobProps,
overrides?: Partial<JobProps>
) {
// Build config
const fullConfig: Required<DeployJobProps> = {
deployTag: '${{ github.sha }}',
defaultBranch: 'master',
deployTag: "${{ github.sha }}",
defaultBranch: "master",
...config,
};

super(scope, 'deploy', {
runsOn: 'ubuntu-latest',
super(scope, "deploy", {
runsOn: "ubuntu-latest",
if: `github.ref == 'refs/heads/${fullConfig.defaultBranch}'`,
steps: [
{
id: 'synth',
name: 'Synth cdk8s manifests',
id: "synth",
name: "Synth cdk8s manifests",
run: dedent`cd k8s
yarn install --frozen-lockfile
Expand All @@ -55,12 +59,12 @@ export class DeployJob extends CheckoutJob {
yarn build`,
env: {
GIT_SHA: fullConfig.deployTag,
REPOSITORY: '${{ github.repository }}',
AWS_ACCOUNT_ID: '${{ secrets.AWS_ACCOUNT_ID }}',
REPOSITORY: "${{ github.repository }}",
AWS_ACCOUNT_ID: "${{ secrets.AWS_ACCOUNT_ID }}",
},
},
{
name: 'Deploy',
name: "Deploy",
run: dedent`aws eks --region us-east-1 update-kubeconfig --name production --role-arn arn:aws:iam::\${AWS_ACCOUNT_ID}:role/kubectl
# get repo name from synth step
Expand All @@ -70,9 +74,9 @@ export class DeployJob extends CheckoutJob {
kubectl apply -f k8s/dist/ -l app.kubernetes.io/component=certificate
kubectl apply -f k8s/dist/ --prune -l app.kubernetes.io/part-of=$RELEASE_NAME`,
env: {
AWS_ACCOUNT_ID: '${{ secrets.AWS_ACCOUNT_ID }}',
AWS_ACCESS_KEY_ID: '${{ secrets.GH_AWS_ACCESS_KEY_ID }}',
AWS_SECRET_ACCESS_KEY: '${{ secrets.GH_AWS_SECRET_ACCESS_KEY }}',
AWS_ACCOUNT_ID: "${{ secrets.AWS_ACCOUNT_ID }}",
AWS_ACCESS_KEY_ID: "${{ secrets.GH_AWS_ACCESS_KEY_ID }}",
AWS_SECRET_ACCESS_KEY: "${{ secrets.GH_AWS_SECRET_ACCESS_KEY }}",
},
},
],
Expand Down
Loading

0 comments on commit efd8251

Please sign in to comment.