Skip to content
Open
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
40 changes: 40 additions & 0 deletions .github/actions/cleanup-deployments/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0 OR ISC

name: 'cleanup-deployments'
description: 'Removes deployment entries from the PR timeline created by environment-gated jobs. Marks each deployment as inactive then deletes it. Does not affect CI check results.'
runs:
using: 'composite'
steps:
- uses: actions/github-script@v8
if: github.event_name == 'pull_request_target'
with:
script: |
const sha = context.payload.pull_request?.head?.sha || context.sha;
for (const env of ['auto-approve']) {
const deployments = await github.rest.repos.listDeployments({
owner: context.repo.owner,
repo: context.repo.repo,
environment: env,
sha: sha,
per_page: 100,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presumably 100 is enough today, but do we have to limit page size? if the page size grows >100, do we need to paginate here?

});
console.log(`Found ${deployments.data.length} deployments for ${env} (sha: ${sha})`);
for (const d of deployments.data) {
try {
await github.rest.repos.createDeploymentStatus({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do we even use this notion of "deployments" for? instead of cleaning up the unneeded deployments, can we just disable them altogether?

owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: d.id,
state: 'inactive',
});
await github.rest.repos.deleteDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: d.id,
});
} catch (e) {
console.log(`Failed to delete deployment ${d.id}: ${e.message}`);
}
}
}
12 changes: 12 additions & 0 deletions .github/workflows/android-omnibus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
permissions:
id-token: write
contents: read
deployments: write

jobs:
authorization-check:
Expand Down Expand Up @@ -76,3 +77,14 @@ jobs:
--release ${{ matrix.release }} \
--shared ${{ matrix.shared }} \
--action start-job


cleanup-deployments:
if: always()
needs: [device-farm]
runs-on: ubuntu-latest
permissions:
deployments: write
steps:
- uses: actions/checkout@v5
- uses: ./.github/actions/cleanup-deployments
12 changes: 12 additions & 0 deletions .github/workflows/image-build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ env:
permissions:
id-token: write
contents: read
deployments: write

jobs:
authorization-check:
Expand Down Expand Up @@ -123,3 +124,14 @@ jobs:
- name: Push Images
run: |
docker push ${{ steps.images.outputs.latest }}


cleanup-deployments:
if: always()
needs: [build, push]
runs-on: ubuntu-latest
permissions:
deployments: write
steps:
- uses: actions/checkout@v5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why v5 here but v4 below?

- uses: ./.github/actions/cleanup-deployments
11 changes: 11 additions & 0 deletions .github/workflows/security-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ concurrency:
cancel-in-progress: true
permissions:
contents: read
deployments: write

jobs:
authorize:
Expand Down Expand Up @@ -82,3 +83,13 @@ jobs:
-H "Authorization: token ${GH_TOKEN}" \
"${STATUS_URL}" \
-d "{\"state\":\"${STATE}\",\"context\":\"security-review / report\",\"target_url\":\"${REPORT_URL}\"}"

cleanup-deployments:
if: always()
needs: [execute]
runs-on: ubuntu-latest
permissions:
deployments: write
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/cleanup-deployments
Loading