Skip to content

Commit

Permalink
Release 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ArmaanT committed Jan 6, 2021
1 parent 6309e35 commit 5ec76cb
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 60 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.2.0 (2021-01-05)

* Migrate from dedent-js to ts-dedent
* Leave dedent commented out by default in ts init
* Update js-yaml to 4.0.0 and remove custom yaml formatting workarounds

## 0.1.4 (2020-12-23)

* Update aws constructs (accidental major bump)
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript/pypi-publish/.github/cdk/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as dedent from 'dedent-js';
import dedent from 'ts-dedent';
import { Construct } from "constructs";
import { App, Stack, Workflow, Job } from "cdkactions";

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"npmClient": "yarn",
"useWorkspaces": true,
"version": "0.1.4"
"version": "0.2.0"
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"examples/**/*"
],
"nohoist": [
"cdkactions/dedent-js",
"cdkactions/dedent-js/**",
"cdkactions/ts-dedent",
"cdkactions/ts-dedent/**",
"cdkactions/js-yaml",
"cdkactions/js-yaml/**",
"cdkactions/yaml",
Expand Down
2 changes: 1 addition & 1 deletion packages/cdkactions-cli/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2020 Armaan Tobaccowalla
Copyright 2021 Armaan Tobaccowalla

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion packages/cdkactions-cli/templates/typescript-app/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as dedent from 'dedent-js';
// import dedent from 'ts-dedent';
import { Construct } from "constructs";
import { App, Stack } from "cdkactions";

Expand Down
4 changes: 2 additions & 2 deletions packages/cdkactions/.projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const project = new JsiiProject({

peerDeps: ['constructs'],
devDeps: ['constructs', '@types/js-yaml'],
deps: ['js-yaml', 'dedent-js'],
deps: ['js-yaml', 'ts-dedent'],
bundledDeps: [
"js-yaml",
"dedent-js",
"ts-dedent",
],

python: {
Expand Down
2 changes: 1 addition & 1 deletion packages/cdkactions/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2020 Armaan Tobaccowalla
Copyright 2021 Armaan Tobaccowalla

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
10 changes: 5 additions & 5 deletions packages/cdkactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"devDependencies": {
"@types/jest": "^26.0.7",
"@types/js-yaml": "^3.12.5",
"@types/js-yaml": "^4.0.0",
"@types/node": "^10.17.0",
"@typescript-eslint/eslint-plugin": "^4.3.0",
"@typescript-eslint/parser": "^4.3.0",
Expand All @@ -57,12 +57,12 @@
"constructs": "^3.2.80"
},
"dependencies": {
"dedent-js": "^1.0.1",
"js-yaml": "^3.14.1"
"js-yaml": "^4.0.0",
"ts-dedent": "^2.0.0"
},
"bundledDependencies": [
"dedent-js",
"js-yaml"
"js-yaml",
"ts-dedent"
],
"keywords": [
"actions",
Expand Down
2 changes: 1 addition & 1 deletion packages/cdkactions/src/library.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Construct } from 'constructs';
import * as dedent from 'dedent-js';
import dedent from 'ts-dedent';
import { Job, JobProps, StepsProps } from './job';
import { Stack } from './stack';
import { Workflow } from './workflow';
Expand Down
5 changes: 2 additions & 3 deletions packages/cdkactions/src/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as fs from 'fs';
import * as path from 'path';
import { Construct, ISynthesisSession, Node } from 'constructs';
import * as yaml from 'js-yaml';
import { formatGHActionsYaml } from './utils';
import { Workflow } from './workflow';

/**
Expand Down Expand Up @@ -35,11 +34,11 @@ export class Stack extends Construct {
const workflowOutput = path.join(session.outdir, child.outputFile);

// Get raw yaml of workflow
const rawYaml = yaml.safeDump(child.toGHAction(), { lineWidth: -1 });
const rawYaml = yaml.dump(child.toGHAction(), { lineWidth: -1, noCompatMode: true, quotingType: '"' });

// Save the formatted yaml
fs.writeFileSync(workflowOutput, `# Generated by cdkactions. Do not modify\n# Generated as part of the '${this.id}' stack.\n`);
fs.writeFileSync(workflowOutput, formatGHActionsYaml(rawYaml), { flag: 'a' });
fs.writeFileSync(workflowOutput, rawYaml, { flag: 'a' });
}
}
}
Expand Down
28 changes: 0 additions & 28 deletions packages/cdkactions/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
import { StringMap } from './types';

/**
* Fix the raw yaml returned by yaml.safeDump by removing quotes surrounding GH Action
* expressions, removing double single quotes from within a GH Action expression,
* and finally remove quotes from the top-level "on" key
* @param rawYaml Raw yaml to be formatted
*/
export const formatGHActionsYaml = (rawYaml: string) => {
// Remove quotes from GH Action expressions: ${{ ... }}
const expression_re = /'(\${{ .* }})'/g;
const fixedExpression = rawYaml.replace(expression_re, '$1');

// Remove double single quotes from inside GH Action expressions:
const double_re = /\${{ .*''.* }}/g;
const removeDoubleQuote = (match: string, _offset: string, _string: string) => {
return match.replace(/''/g, '\'');
};
const fixedDoubleQuotes = fixedExpression.replace(double_re, removeDoubleQuote);

// Remove quotes from the top-level "on" key
const on_re = /'on':/g;
const fixedOn = fixedDoubleQuotes.replace(on_re, 'on:');

// Removes nested single quotes like in "key: '${{ hashFiles('example/yarn.lock') }}'"
const nested_re = /: '([^'\n\r]*'[^'\n\r]*'.*)'\n/g;
const fixedNested = fixedOn.replace(nested_re, ': $1\n');

return fixedNested;
};

/**
* A helper function to recursively rename keys within an object
Expand Down
6 changes: 3 additions & 3 deletions packages/cdkactions/test/__snapshots__/synth.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Cache
uses: actions/cache@v2
with:
path: '**/files'
path: \\"**/files\\"
key: v0-\${{ hashFiles('Dockerfile') }}
- name: Build docker
uses: docker/build-push-action@v1
Expand All @@ -31,7 +31,7 @@ jobs:
username: \${{ secrets.DOCKER_USERNAME }}
password: \${{ secrets.DOCKER_PASSWORD }}
push: \${{ github.ref == 'refs/heads/master' }}
tags: 'latest,\${{ github.sha }}'
tags: latest,\${{ github.sha }}
continue-on-error: false
continue-on-error: false
"
Expand All @@ -55,7 +55,7 @@ exports[`complicated stack 3`] = `
name: Cron
on:
schedule:
- cron: '*/15 * * * *'
- cron: \\"*/15 * * * *\\"
jobs:
matrix:
runs-on: \${{ matrix.os }}
Expand Down
1 change: 0 additions & 1 deletion packages/cdkactions/test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { camelToSnake, renameKeys } from '../src/utils';

// TODO: test formatGHActionsYaml

test('renameKeys', () => {
const obj = { oldKey: 'value', arr: [{ oldKey: 'different value' }] };
Expand Down
32 changes: 22 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1502,10 +1502,10 @@
jest-diff "^26.0.0"
pretty-format "^26.0.0"

"@types/js-yaml@^3.12.5":
version "3.12.5"
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.12.5.tgz#136d5e6a57a931e1cce6f9d8126aa98a9c92a6bb"
integrity sha512-JCcp6J0GV66Y4ZMDAQCXot4xprYB+Zfd3meK9+INSJeVZwJmHAW30BBEEkPzXswMXuiyReUGOP3GxrADc9wPww==
"@types/js-yaml@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.0.tgz#d1a11688112091f2c711674df3a65ea2f47b5dfb"
integrity sha512-4vlpCM5KPCL5CfGmTbpjwVKbISRYhduEJvvUWsH5EB7QInhEj94XPZ3ts/9FPiLZFqYO0xoW4ZL8z2AabTGgJA==

"@types/json-schema@^7.0.3":
version "7.0.6"
Expand Down Expand Up @@ -1829,6 +1829,11 @@ argparse@^1.0.7:
dependencies:
sprintf-js "~1.0.2"

argparse@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==

[email protected]:
version "0.0.2"
resolved "https://registry.yarnpkg.com/argv/-/argv-0.0.2.tgz#ecbd16f8949b157183711b1bda334f37840185ab"
Expand Down Expand Up @@ -2970,11 +2975,6 @@ decode-uri-component@^0.2.0:
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=

dedent-js@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/dedent-js/-/dedent-js-1.0.1.tgz#bee5fb7c9e727d85dffa24590d10ec1ab1255305"
integrity sha1-vuX7fJ5yfYXf+iRZDRDsGrElUwU=

dedent@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/dedent/-/dedent-0.7.0.tgz#2495ddbaf6eb874abb0e1be9df22d2e5a544326c"
Expand Down Expand Up @@ -5237,14 +5237,21 @@ [email protected]:
argparse "^1.0.7"
esprima "^4.0.0"

js-yaml@^3.13.1, js-yaml@^3.14.1:
js-yaml@^3.13.1:
version "3.14.1"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.1.tgz#dae812fdb3825fa306609a8717383c50c36a0537"
integrity sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"

js-yaml@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.0.0.tgz#f426bc0ff4b4051926cd588c71113183409a121f"
integrity sha512-pqon0s+4ScYUvX30wxQi3PogGFAlUyH0awepWvwkj4jD4v+ova3RiYw8bmA6x2rDrEaj8i/oWKoRxpVNW+Re8Q==
dependencies:
argparse "^2.0.1"

jsbn@~0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
Expand Down Expand Up @@ -8154,6 +8161,11 @@ trim-off-newlines@^1.0.0:
resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3"
integrity sha1-n5up2e+odkw4dpi8v+sshI8RrbM=

ts-dedent@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ts-dedent/-/ts-dedent-2.0.0.tgz#47c5eb23d9096f3237cc413bc82d387d36dbe690"
integrity sha512-DfxKjSFQfw9+uf7N9Cy8Ebx9fv5fquK4hZ6SD3Rzr+1jKP6AVA6H8+B5457ZpUs0JKsGpGqIevbpZ9DMQJDp1A==

ts-jest@^26.1.0:
version "26.4.4"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.4.4.tgz#61f13fb21ab400853c532270e52cc0ed7e502c49"
Expand Down

0 comments on commit 5ec76cb

Please sign in to comment.