Skip to content

Commit 7ea8651

Browse files
authored
Add a switch to ignore the sequence check (#9)
Useful if, for example, the workflow file is renamed and GHA starts counting workflow runs from #1 again.
1 parent cbc07d4 commit 7ea8651

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ This workaround should catch a good share of possible out-of-order deployments.
164164
### Input
165165

166166
* `application`: The name of the CodeDeploy Application to work with. Defaults to the "short" repo name.
167+
* `skip-sequence-check`: When set to `true`, do not attempt to make sure deployments happen in order. Use this when the workflow count has been reset or changed to a lower value; possible cause is renaming the workflow file.
167168

168169
### Outputs
169170

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ description: 'An Action to deploy GitHub repos with AWS CodeDeploy'
33
inputs:
44
application:
55
description: 'AWS CodeDeploy application name; defaults to short repository name'
6+
skip-sequence-check:
7+
description: 'When set, skip the check making sure no earlier workflow results are deployed'
8+
default: false
69
outputs:
710
deploymentId:
811
description: AWS CodeDeployment Deployment-ID of the deployment created

cli.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979

8080
const action = require('./create-deployment');
8181
try {
82-
await action.createDeployment(applicationName, fullRepositoryName, branchName, commitId, null, core);
82+
await action.createDeployment(applicationName, fullRepositoryName, branchName, commitId, null, null, core);
8383
} catch (e) {
8484
console.log(`👉🏻 ${e.message}`);
8585
process.exit(1);

create-deployment.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function fetchBranchConfig(branchName) {
2323
process.exit();
2424
}
2525

26-
exports.createDeployment = async function(applicationName, fullRepositoryName, branchName, commitId, runNumber, core) {
26+
exports.createDeployment = async function(applicationName, fullRepositoryName, branchName, commitId, runNumber, skipSequenceCheck, core) {
2727
const branchConfig = fetchBranchConfig(branchName);
2828
const safeBranchName = branchName.replace(/[^a-z0-9-/]+/gi, '-').replace(/\/+/, '--');
2929
const deploymentGroupName = branchConfig.deploymentGroupName ? branchConfig.deploymentGroupName.replace('$BRANCH', safeBranchName) : safeBranchName;
@@ -74,7 +74,7 @@ exports.createDeployment = async function(applicationName, fullRepositoryName, b
7474
return;
7575
}
7676

77-
if (runNumber) {
77+
if (!skipSequenceCheck && runNumber) {
7878
var {deploymentGroupInfo: {lastAttemptedDeployment: {deploymentId: lastAttemptedDeploymentId} = {}}} = await codeDeploy.getDeploymentGroup({
7979
applicationName: applicationName,
8080
deploymentGroupName: deploymentGroupName,

dist/index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function fetchBranchConfig(branchName) {
3939
process.exit();
4040
}
4141

42-
exports.createDeployment = async function(applicationName, fullRepositoryName, branchName, commitId, runNumber, core) {
42+
exports.createDeployment = async function(applicationName, fullRepositoryName, branchName, commitId, runNumber, skipSequenceCheck, core) {
4343
const branchConfig = fetchBranchConfig(branchName);
4444
const safeBranchName = branchName.replace(/[^a-z0-9-/]+/gi, '-').replace(/\/+/, '--');
4545
const deploymentGroupName = branchConfig.deploymentGroupName ? branchConfig.deploymentGroupName.replace('$BRANCH', safeBranchName) : safeBranchName;
@@ -90,7 +90,7 @@ exports.createDeployment = async function(applicationName, fullRepositoryName, b
9090
return;
9191
}
9292

93-
if (runNumber) {
93+
if (!skipSequenceCheck && runNumber) {
9494
var {deploymentGroupInfo: {lastAttemptedDeployment: {deploymentId: lastAttemptedDeploymentId} = {}}} = await codeDeploy.getDeploymentGroup({
9595
applicationName: applicationName,
9696
deploymentGroupName: deploymentGroupName,
@@ -193,12 +193,15 @@ exports.createDeployment = async function(applicationName, fullRepositoryName, b
193193
const isPullRequest = payload.pull_request !== undefined;
194194
const commitId = isPullRequest ? payload.pull_request.head.sha : payload.head_commit.id; // like "ec26c3e57ca3a959ca5aad62de7213c562f8c821"
195195
const branchName = isPullRequest ? payload.pull_request.head.ref : payload.ref.replace(/^refs\/heads\//, ''); // like "my/branch_name"
196+
197+
const skipSequenceCheck = core.getBooleanInput('skip-sequence-check');
198+
196199
console.log(`🎋 On branch '${branchName}', head commit ${commitId}`);
197200

198201
const runNumber = process.env['github_run_number'] || process.env['GITHUB_RUN_NUMBER'];
199202

200203
try {
201-
action.createDeployment(applicationName, fullRepositoryName, branchName, commitId, runNumber, core);
204+
action.createDeployment(applicationName, fullRepositoryName, branchName, commitId, runNumber, skipSequenceCheck, core);
202205
} catch (e) {}
203206
})();
204207

index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
const isPullRequest = payload.pull_request !== undefined;
1313
const commitId = isPullRequest ? payload.pull_request.head.sha : payload.head_commit.id; // like "ec26c3e57ca3a959ca5aad62de7213c562f8c821"
1414
const branchName = isPullRequest ? payload.pull_request.head.ref : payload.ref.replace(/^refs\/heads\//, ''); // like "my/branch_name"
15+
16+
const skipSequenceCheck = core.getBooleanInput('skip-sequence-check');
17+
1518
console.log(`🎋 On branch '${branchName}', head commit ${commitId}`);
1619

1720
const runNumber = process.env['github_run_number'] || process.env['GITHUB_RUN_NUMBER'];
1821

1922
try {
20-
action.createDeployment(applicationName, fullRepositoryName, branchName, commitId, runNumber, core);
23+
action.createDeployment(applicationName, fullRepositoryName, branchName, commitId, runNumber, skipSequenceCheck, core);
2124
} catch (e) {}
2225
})();

0 commit comments

Comments
 (0)