Skip to content

Commit

Permalink
make configuring testing mode its own prerequisite job
Browse files Browse the repository at this point in the history
Signed-off-by: Sumu <[email protected]>
  • Loading branch information
sumupitchayan committed Oct 19, 2023
1 parent cfeab4b commit 92aea9d
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 61 deletions.
47 changes: 34 additions & 13 deletions .github/workflows/bump-latest-cdk8s-plus-library.yml

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

96 changes: 50 additions & 46 deletions src/k8s-automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class K8sVersionUpgradeAutomation extends Component {

const runsOn = ['ubuntu-latest'];

// PART 0: Check Latest Kubernetes Version Online
// PART 0: Check Latest Kubernetes Version Online and configure Testing Mode

const checkLatestVersion: workflows.Job = {
runsOn: runsOn,
Expand Down Expand Up @@ -93,28 +93,62 @@ export class K8sVersionUpgradeAutomation extends Component {
};

workflow.addJob('check-latest-k8s-release', checkLatestVersion);
// PART 1: Prerequisite

const generateK8sSpecJob: workflows.Job = {
const configureTestingMode: workflows.Job = {
runsOn: runsOn,
permissions: {
contents: workflows.JobPermission.READ,
pullRequests: workflows.JobPermission.WRITE,
},
needs: ['check-latest-k8s-release'],
if: 'needs.check-latest-k8s-release.outputs.httpStatus != 200',
env: {
testingMode: 'true',
outputs: {
testingMode: {
stepId: 'set-testing-mode-var',
outputName: 'testingMode',
},
labels: {
stepId: 'set-auto-approve-label',
outputName: 'labels',
},
},
steps: [
{
name: 'Checkout',
uses: 'actions/checkout@v2',
},
{
name: 'Set testingMode env variable',
name: 'Set testingMode environment variable',
id: 'set-testing-mode-var',
run: 'bash src/testModeSet.sh ${{ github.event.inputs.testingMode }}',
},
{
name: 'Set auto-approve label for PR',
id: 'set-auto-approve-label',
run: 'if [${{steps.set-testing-mode-var.outputs.testingMode}} = "true"];then echo labels="auto-approve" >> $GITHUB_OUTPUT;fi',
env: { GITHUB_TOKEN: '${{ secrets.PROJEN_GITHUB_TOKEN }}' },
continueOnError: false,
},
],
};

workflow.addJob('configure-testing-mode', configureTestingMode);

// PART 1: Prerequisite

const generateK8sSpecJob: workflows.Job = {
runsOn: runsOn,
permissions: {
contents: workflows.JobPermission.READ,
pullRequests: workflows.JobPermission.WRITE,
},
needs: ['check-latest-k8s-release', 'configure-testing-mode'],
if: 'needs.check-latest-k8s-release.outputs.httpStatus != 200',
steps: [
{
name: 'Checkout',
uses: 'actions/checkout@v2',
},
{
name: 'Setup Node.js',
uses: 'actions/setup-node@v2',
Expand All @@ -130,26 +164,13 @@ export class K8sVersionUpgradeAutomation extends Component {
env: { GITHUB_TOKEN: '${{ secrets.PROJEN_GITHUB_TOKEN }}' },
continueOnError: false,
},
{
name: 'Set auto-approve label for PR if in testing mode',
id: 'set-auto-approve-label',
// if: '!(${{ github.event_name }} == "push")',
// run: 'echo labels="bug" >> $GITHUB_OUTPUT;',
//${{ github.event.inputs.testingMode }}
// run: 'bash src/testingModeScript.sh ${{ github.event_name }} ${{ github.event.inputs.testingMode }}',
run: 'if [$testingMode = "true"];then echo labels="auto-approve" >> $GITHUB_OUTPUT;fi',
// if: 'github.event.inputs.testingMode == false',
// run: 'echo labels="auto-approve" >> $GITHUB_OUTPUT',
env: { GITHUB_TOKEN: '${{ secrets.PROJEN_GITHUB_TOKEN }}' },
continueOnError: false,
},
...WorkflowActions.createPullRequest({
workflowName: 'create-pull-request',
pullRequestTitle: 'chore: v${{ needs.check-latest-k8s-release.outputs.latestVersion }}${{ steps.set-auto-approve-label.outputs.labels }} kubernetes-spec',
pullRequestDescription: 'This PR adds the v${{ needs.check-latest-k8s-release.outputs.latestVersion }} Kubernetes spec. This is required in order for us to add a new version to cdk8s-plus.',
branchName: 'github-actions/generate-k8s-spec-${{ needs.check-latest-k8s-release.outputs.latestVersion }}${{ steps.set-auto-approve-label.outputs.labels }}',
labels: [
'${{ steps.set-auto-approve-label.outputs.labels }}',
'${{ needs.configure-testing-mode.set-auto-approve-label.outputs.labels }}',
],
credentials: GithubCredentials.fromPersonalAccessToken(),
}),
Expand All @@ -164,7 +185,7 @@ export class K8sVersionUpgradeAutomation extends Component {
contents: workflows.JobPermission.READ,
pullRequests: workflows.JobPermission.WRITE,
},
needs: ['check-latest-k8s-release'],
needs: ['check-latest-k8s-release', 'configure-testing-mode'],
if: 'needs.check-latest-k8s-release.outputs.httpStatus != 200',
steps: [
{
Expand Down Expand Up @@ -195,7 +216,7 @@ export class K8sVersionUpgradeAutomation extends Component {
contents: workflows.JobPermission.READ,
pullRequests: workflows.JobPermission.WRITE,
},
needs: ['check-latest-k8s-release', 'generate-new-k8s-spec'],
needs: ['check-latest-k8s-release', 'generate-new-k8s-spec', 'configure-testing-mode'],
steps: [
{
name: 'Checkout',
Expand Down Expand Up @@ -230,11 +251,8 @@ export class K8sVersionUpgradeAutomation extends Component {
run: 'yarn run import',
},
{
// TESTING MODE: Disable publishing. Delete / comment this out before running it for real.
// if: '${{ github.event.inputs.testingMode }} == true',
// name: 'Disable publishing if testingMode is true',
name: 'Disable publishing',
run: 'npx projen disable-publishing',
run: 'if [${{ needs.configure-testing-mode.outputs.testingMode }}"true"];then npx projen disable-publishing;fi',
},
{
name: 'Test package json output',
Expand Down Expand Up @@ -282,7 +300,7 @@ export class K8sVersionUpgradeAutomation extends Component {
pullRequests: workflows.JobPermission.WRITE,
},
// add the cdk8s-plus update job to needs when it's done:
needs: ['check-latest-k8s-release', 'create-new-plus-branch'],
needs: ['check-latest-k8s-release', 'create-new-plus-branch', 'configure-testing-mode'],
if: 'needs.check-latest-k8s-release.outputs.httpStatus != 200',
steps: [
{
Expand Down Expand Up @@ -315,36 +333,30 @@ export class K8sVersionUpgradeAutomation extends Component {
env: { GITHUB_TOKEN: '${{ secrets.PROJEN_GITHUB_TOKEN }}' },
continueOnError: false,
},
// {
// name: 'Set auto-approve label for PR if in testing mode',
// id: 'set-auto-approve-label',
// if: '${{ github.event.inputs.testingMode }} == false',
// run: 'echo labels="auto-approve" >> $GITHUB_OUTPUT',
// env: { GITHUB_TOKEN: '${{ secrets.PROJEN_GITHUB_TOKEN }}' },
// continueOnError: false,
// },
...WorkflowActions.createPullRequest({
workflowName: 'create-pull-request',
pullRequestTitle: 'chore(website): cdk8s-plus-${{ needs.check-latest-k8s-release.outputs.latestVersion }}',
pullRequestDescription: 'This PR updates the website with the latest version of cdk8s-plus.',
branchName: 'github-actions/website-update-${{ needs.check-latest-k8s-release.outputs.latestVersion }}',
credentials: GithubCredentials.fromPersonalAccessToken(),
labels: [
// '${{ steps.set-auto-approve-label.outputs.labels }}',
'${{ needs.configure-testing-mode.set-auto-approve-label.outputs.labels }}',
],
}),
],
};

workflow.addJob('update-cdk8s-website', updateCdk8s);

// PART 4: Update CDK Ops

const updateCdkOps: workflows.Job = {
runsOn: runsOn,
permissions: {
contents: workflows.JobPermission.READ,
pullRequests: workflows.JobPermission.WRITE,
},
needs: ['check-latest-k8s-release', 'update-cdk8s-website'],
needs: ['check-latest-k8s-release', 'update-cdk8s-website', 'configure-testing-mode'],
steps: [
{
name: 'Checkout',
Expand All @@ -360,21 +372,13 @@ export class K8sVersionUpgradeAutomation extends Component {
env: { GITHUB_TOKEN: '${{ secrets.PROJEN_GITHUB_TOKEN }}' },
continueOnError: false,
},
// {
// name: 'Set auto-approve label for PR if in testing mode',
// id: 'set-auto-approve-label',
// if: '${{ github.event.inputs.testingMode }} == false',
// run: 'echo labels="auto-approve" >> $GITHUB_OUTPUT',
// env: { GITHUB_TOKEN: '${{ secrets.PROJEN_GITHUB_TOKEN }}' },
// continueOnError: false,
// },
...WorkflowActions.createPullRequest({
workflowName: 'create-pull-request',
pullRequestTitle: 'chore: updating latest cdk8s-plus version to v${{ needs.check-latest-k8s-release.outputs.latestVersion }}',
pullRequestDescription: 'This PR updates the reference to of the latest cdk8s-plus version',
branchName: 'github-actions/cdk-ops-k8s-upgrade-${{ needs.check-latest-k8s-release.outputs.latestVersion }}',
labels: [
// // '${{ steps.set-auto-approve-label.outputs.labels }}',
'${{ needs.configure-testing-mode.set-auto-approve-label.outputs.labels }}',
],
credentials: GithubCredentials.fromPersonalAccessToken(),
}),
Expand Down
3 changes: 1 addition & 2 deletions src/testModeSet.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash

TESTING_MODE_INPUT="$1"
echo testingMode=${TESTING_MODE_INPUT:-"true"} >> $GITHUB_ENV
# echo testingMode=${TESTING_MODE_INPUT:-"true"}
echo testingMode=${TESTING_MODE_INPUT:-"true"} >> >> $GITHUB_OUTPUT

0 comments on commit 92aea9d

Please sign in to comment.