Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cage-options #32

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ jobs:
run: |
make
git diff --exit-code
- run: npm test
41 changes: 22 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ Before using action, ensure `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` adde
`secrets.GITHUB_TOKEN` is automatically added within actions.

```yaml
jobs:
deploy:
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: loilo-inc/actions-setup-cage@v5
- uses: loilo-inc/actions-deploy-cage@v4
with:
region: us-west-2
deploy-context: .deploy/development/your-service
create-deployment: true
environment: development
github-repository: ${{ github.repository }}
github-token: ${{ env.GITHUB_TOKEN }}
github-ref: ${{ github.sha }}
jobs:
deploy:
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: loilo-inc/actions-setup-cage@v5
- uses: loilo-inc/actions-deploy-cage@v4
with:
region: us-west-2
# canarycage options in addition to region
cage-options: --canaryTaskIdleDuration 60
deploy-context: .deploy/development/your-service
# github deployment options
create-deployment: true
environment: development
github-repository: ${{ github.repository }}
github-token: ${{ env.GITHUB_TOKEN }}
github-ref: ${{ github.sha }}
```
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ inputs:
canary-task-idle-duration:
description: "--canaryTaskIdleDuration for cage"
required: false
deprecationMessage: "canary-task-idle-duration is deprecated. Use cage-options instead."
update-service:
description: "--updateService for cage (>=4.0)"
required: false
deprecationMessage: "update-service is deprecated. Use cage-options instead."
cage-options:
description: "Options for cage rollout. Value shold be string. e.g. '--canaryTaskIdleDuration 10 --updateService'"
required: false
environment:
description: "Arbitrary release environment for github deployment. e.g. development,staging,production... Required by --create-deployment"
required: false
Expand Down
83 changes: 66 additions & 17 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30417,6 +30417,54 @@ function wrappy (fn, cb) {
}


/***/ }),

/***/ 4106:
/***/ ((__unused_webpack_module, exports) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.parseStringToArgs = void 0;
function parseStringToArgs(rawArgs) {
// parse string like '--canaryTaskIdleDuration "value of any" --updateService'
// into ['--canaryTaskIdleDuration', 'value of any', '--updateService']
let idx = 0;
let args = [];
function skipWs() {
while (idx < rawArgs.length && rawArgs[idx] === " ") {
idx += 1;
}
}
function readValue() {
skipWs();
let value = "";
let quoteType = null;
if (rawArgs[idx] === '"' || rawArgs[idx] === "'") {
quoteType = rawArgs[idx];
idx += 1;
}
while (idx < rawArgs.length) {
if (quoteType && rawArgs[idx] === quoteType) {
idx += 1;
break;
}
if (!quoteType && rawArgs[idx] === " ") {
break;
}
value += rawArgs[idx];
idx += 1;
}
return value;
}
while (idx < rawArgs.length) {
args.push(readValue());
}
return args;
}
exports.parseStringToArgs = parseStringToArgs;


/***/ }),

/***/ 5930:
Expand Down Expand Up @@ -30459,7 +30507,7 @@ function aggregateDeploymentParams({ environment, ref, token, repository, }) {
};
}
exports.aggregateDeploymentParams = aggregateDeploymentParams;
async function deploy({ deployContext, region, deployment, idleDuration, updateService, }) {
async function deploy({ deployment, args, }) {
let github;
let deployId;
if (deployment) {
Expand Down Expand Up @@ -30497,15 +30545,7 @@ async function deploy({ deployContext, region, deployment, idleDuration, updateS
},
});
}
let opts = [`--region ${region}`];
if (idleDuration) {
opts.push(`--canaryTaskIdleDuration ${idleDuration}`);
}
if (updateService) {
opts.push("--updateService");
}
const cmd = `cage rollout ${opts.join(" ")} ${deployContext}`;
code = await exec.exec(cmd);
code = await exec.exec("cage", ["rollout", ...args]);
}
catch (e) {
if (e instanceof Error) {
Expand Down Expand Up @@ -32460,8 +32500,10 @@ var __webpack_exports__ = {};
var exports = __webpack_exports__;

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.main = void 0;
const core = __nccwpck_require__(2186);
const deploy_1 = __nccwpck_require__(5930);
const args_1 = __nccwpck_require__(4106);
function boolify(s) {
return s !== "" && !s.match(/^(false|0|undefined|null)$/);
}
Expand All @@ -32479,6 +32521,7 @@ async function main() {
const environment = core.getInput("environment");
const idleDuration = core.getInput("canary-task-idle-duration");
const updateService = boolify(core.getInput("update-service"));
const cageOptions = core.getInput("cage-options");
const token = core.getInput("github-token");
const ref = core.getInput("github-ref");
const repository = core.getInput("github-repository");
Expand All @@ -32492,13 +32535,18 @@ async function main() {
token,
});
}
await (0, deploy_1.deploy)({
deployContext,
region,
deployment,
idleDuration,
updateService,
});
const args = ["--region", region];
if (idleDuration) {
args.push("--canaryTaskIdleDuration", idleDuration);
}
if (updateService) {
args.push("--updateService");
}
if (cageOptions) {
args.push(...(0, args_1.parseStringToArgs)(cageOptions));
}
args.push(deployContext);
await (0, deploy_1.deploy)({ deployment, args });
}
catch (e) {
if (e instanceof Error) {
Expand All @@ -32507,6 +32555,7 @@ async function main() {
core.setFailed("see error above");
}
}
exports.main = main;
if (require.main === require.cache[eval('__filename')]) {
main();
}
Expand Down
Loading