|
| 1 | +import * as dedent from 'dedent-js'; |
| 2 | +import { Construct } from "constructs"; |
| 3 | +import { App, Stack, Workflow, Job } from "cdkactions"; |
| 4 | + |
| 5 | +export class JSIIReleaseStack extends Stack { |
| 6 | + constructor(scope: Construct, name: string) { |
| 7 | + super(scope, name); |
| 8 | + |
| 9 | + // Build workflow |
| 10 | + const build = new Workflow(this, "build", { |
| 11 | + name: 'Build', |
| 12 | + on: ["pullRequest", "push"] |
| 13 | + }); |
| 14 | + |
| 15 | + new Job(build, 'build', { |
| 16 | + runsOn: 'ubuntu-latest', |
| 17 | + container: { |
| 18 | + image: 'jsii/superchain' |
| 19 | + }, |
| 20 | + steps: [ |
| 21 | + { uses: 'actions/checkout@v2' }, |
| 22 | + { |
| 23 | + name: 'Install dependencies', |
| 24 | + run: 'yarn install' |
| 25 | + }, |
| 26 | + { |
| 27 | + name: 'Compile', |
| 28 | + run: dedent`tools/align-version.sh |
| 29 | + yarn build` |
| 30 | + }, |
| 31 | + { |
| 32 | + name: 'Unit Tests', |
| 33 | + run: 'yarn test' |
| 34 | + }, |
| 35 | + { |
| 36 | + name: 'Code Coverage', |
| 37 | + run: 'yarn codecov' |
| 38 | + }, |
| 39 | + { |
| 40 | + name: 'Create Bundle', |
| 41 | + run: 'yarn package' |
| 42 | + }, |
| 43 | + { |
| 44 | + name: 'Integration Tests', |
| 45 | + // run: 'yarn integration' |
| 46 | + run: 'echo TODO: add these' |
| 47 | + } |
| 48 | + ] |
| 49 | + }); |
| 50 | + |
| 51 | + // Release workflow |
| 52 | + const release = new Workflow(this, "release", { |
| 53 | + name: 'Release', |
| 54 | + on: { push: { branches: ['master'] } } |
| 55 | + }); |
| 56 | + |
| 57 | + new Job(release, 'build_artifact', { |
| 58 | + name: 'Build and upload artifact', |
| 59 | + if: "github.repository == 'ArmaanT/cdkactions'", |
| 60 | + runsOn: 'ubuntu-latest', |
| 61 | + container: { |
| 62 | + image: 'jsii/superchain' |
| 63 | + }, |
| 64 | + steps: [ |
| 65 | + { uses: 'actions/checkout@v2' }, |
| 66 | + { |
| 67 | + name: 'Install dependencies', |
| 68 | + run: 'yarn install' |
| 69 | + }, |
| 70 | + { |
| 71 | + name: 'Compile', |
| 72 | + run: dedent`tools/align-version.sh |
| 73 | + yarn build` |
| 74 | + }, |
| 75 | + { |
| 76 | + name: 'Unit Tests', |
| 77 | + run: 'yarn test' |
| 78 | + }, |
| 79 | + { |
| 80 | + name: 'Code Coverage', |
| 81 | + run: 'yarn codecov' |
| 82 | + }, |
| 83 | + { |
| 84 | + name: 'Create Bundle', |
| 85 | + run: 'yarn package' |
| 86 | + }, |
| 87 | + { |
| 88 | + name: 'Integration Tests', |
| 89 | + // run: 'yarn integration' |
| 90 | + run: 'echo TODO: add these' |
| 91 | + }, |
| 92 | + { |
| 93 | + name: 'Upload artifact', |
| 94 | + uses: 'actions/upload-artifact@v1', |
| 95 | + with: { |
| 96 | + name: 'dist', |
| 97 | + path: 'dist' |
| 98 | + } |
| 99 | + }, |
| 100 | + { |
| 101 | + name: 'Release to GitHub', |
| 102 | + run: 'tools/release-github.sh', |
| 103 | + env: { |
| 104 | + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}', |
| 105 | + REPO: '${{ github.repository }}', |
| 106 | + } |
| 107 | + }, |
| 108 | + ] |
| 109 | + }); |
| 110 | + |
| 111 | + new Job(release, 'release_npm', { |
| 112 | + name: 'Release to NPM', |
| 113 | + needs: 'build_artifact', |
| 114 | + runsOn: 'ubuntu-latest', |
| 115 | + container: { |
| 116 | + image: 'jsii/superchain' |
| 117 | + }, |
| 118 | + steps: [ |
| 119 | + { |
| 120 | + name: 'Download build artifacts', |
| 121 | + uses: 'actions/download-artifact@v1', |
| 122 | + with: { |
| 123 | + name: 'dist' |
| 124 | + } |
| 125 | + }, |
| 126 | + { |
| 127 | + name: 'Release', |
| 128 | + run: 'npx -p jsii-release jsii-release-npm', |
| 129 | + env: { |
| 130 | + NPM_TOKEN: '${{ secrets.NPM_TOKEN }}' |
| 131 | + } |
| 132 | + } |
| 133 | + ] |
| 134 | + }); |
| 135 | + |
| 136 | + new Job(release, 'release_pypi', { |
| 137 | + name: 'Release to PyPI', |
| 138 | + needs: 'build_artifact', |
| 139 | + runsOn: 'ubuntu-latest', |
| 140 | + container: { |
| 141 | + image: 'jsii/superchain' |
| 142 | + }, |
| 143 | + steps: [ |
| 144 | + { |
| 145 | + name: 'Download build artifacts', |
| 146 | + uses: 'actions/download-artifact@v1', |
| 147 | + with: { |
| 148 | + name: 'dist' |
| 149 | + } |
| 150 | + }, |
| 151 | + { |
| 152 | + name: 'Release', |
| 153 | + run: 'npx -p jsii-release jsii-release-pypi', |
| 154 | + env: { |
| 155 | + TWINE_USERNAME: '${{ secrets.TWINE_USERNAME }}', |
| 156 | + TWINE_PASSWORD: '${{ secrets.TWINE_PASSWORD }}' |
| 157 | + } |
| 158 | + } |
| 159 | + ] |
| 160 | + }); |
| 161 | + } |
| 162 | +} |
| 163 | + |
| 164 | +const app = new App(); |
| 165 | +new JSIIReleaseStack(app, 'jsii'); |
| 166 | +app.synth(); |
0 commit comments