Skip to content

Commit 153e9ac

Browse files
0x46616c6bclaude
andcommitted
merge main and port deactivate_stale_deployments + add mise
- Merge main to include PR #131 (deactivate stale deployments) - Port deactivate_stale_deployments from bash/curl to Octokit in the actions/github-script step - Add mise.toml with bats-core and shellcheck for local dev setup - Update CI workflow to use jdx/mise-action Co-Authored-By: Claude <claude@anthropic.com>
2 parents 1deca16 + cf4adf5 commit 153e9ac

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

action.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,39 @@ runs:
231231
})
232232
)];
233233
234+
// Deactivate stale in-progress/queued/pending deployments for an environment
235+
async function deactivateStaleDeployments(environment) {
236+
const { data: deployments } = await github.rest.repos.listDeployments({
237+
...context.repo,
238+
environment,
239+
per_page: 30
240+
});
241+
242+
for (const dep of deployments) {
243+
const { data: statuses } = await github.rest.repos.listDeploymentStatuses({
244+
...context.repo,
245+
deployment_id: dep.id,
246+
per_page: 1
247+
});
248+
249+
const latestState = statuses[0]?.state;
250+
if (['in_progress', 'queued', 'pending'].includes(latestState)) {
251+
core.info(`Marking stale deployment ${dep.id} (${latestState}) as inactive`);
252+
await github.rest.repos.createDeploymentStatus({
253+
...context.repo,
254+
deployment_id: dep.id,
255+
state: 'inactive',
256+
description: 'Superseded by newer deployment'
257+
});
258+
}
259+
}
260+
}
261+
234262
const ids = {};
235263
for (const env of environments) {
236264
try {
265+
await deactivateStaleDeployments(env);
266+
237267
const { data: deployment } = await github.rest.repos.createDeployment({
238268
...context.repo,
239269
ref: context.sha,

mise.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[tools]
2+
bats-core = "1.11.0"
3+
shellcheck = "0.10.0"
4+
5+
[tasks.test]
6+
description = "Run bats test suite"
7+
run = """
8+
#!/usr/bin/env bash
9+
set -euo pipefail
10+
11+
if [[ ! -d tests/test_helper/bats-support ]]; then
12+
git clone --depth 1 https://github.com/bats-core/bats-support.git tests/test_helper/bats-support
13+
fi
14+
if [[ ! -d tests/test_helper/bats-assert ]]; then
15+
git clone --depth 1 https://github.com/bats-core/bats-assert.git tests/test_helper/bats-assert
16+
fi
17+
18+
bats tests/*.bats
19+
"""
20+
21+
[tasks.lint]
22+
description = "Run shellcheck on all scripts"
23+
run = "shellcheck --severity=warning scripts/*.sh scripts/lib/*.sh"
24+
25+
[tasks.check]
26+
description = "Run all checks (lint + test)"
27+
depends = ["lint", "test"]

0 commit comments

Comments
 (0)