Skip to content

Commit

Permalink
ci: handle concurrent prune tests
Browse files Browse the repository at this point in the history
  • Loading branch information
neilime committed Nov 13, 2023
1 parent 73d0392 commit bf5c1a9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/__main-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ jobs:
needs: ci
uses: ./.github/workflows/prune-pull-requests-images-tags.yml
with:
images: '["application-1", "application-2", "test-prune", "test-delete-image-tags"]'
images: |
[
"application-1",
"application-1/cache",
"application-2",
"application-2/cache",
"test-delete-image-tags",
"test-delete-image-tags/cache"
]
release:
needs: ci
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fi
- id: generate-tag
run: |
RC="-rc.$RANDOM"
RC="-rc.${{ github.run_number }}"
TAG="$(printf '%d.%d.%d%s' $((1+RANDOM%20)) $((1+RANDOM%20)) $((1+RANDOM%20)) "$RC")"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
workflow_call:

env:
IMAGE: "test-prune"
IMAGE: "test-prune-${{ github.run_number }}"

jobs:
setup:
Expand Down Expand Up @@ -33,7 +33,7 @@ jobs:
images: |
[
{
"name": "test-prune",
"name": "test-prune-${{ github.run_number }}",
"context": ".",
"dockerfile": "./tests/application-1/Dockerfile",
"build-args": { "PROD_MODE": "true" },
Expand All @@ -59,8 +59,9 @@ jobs:

- name: Push extra docker image tags for test
run: |
BASE_IMAGE="${{ fromJson(needs.act.outputs.built-images).test-prune.images[0] }}"
BASE_IMAGE=$(echo '${{ needs.act.outputs.built-images }}' | jq -r '."${{ env.IMAGE }}".images[0]')
NEW_IMAGE=ghcr.io/hoverkraft-tech/ci-github-container/${{ env.IMAGE }}:${{ needs.setup.outputs.tag }}
docker pull "$BASE_IMAGE"
docker tag "$BASE_IMAGE" "$NEW_IMAGE"
docker push "$NEW_IMAGE"
Expand Down Expand Up @@ -97,7 +98,7 @@ jobs:
assert.equal(deletedImageTagsForCurrentPullRequest.length, 0, `"deleted-image-tags" output contains current pull request image tag`);
}
- name: Ensure packages have been deleted
- name: Ensure packages versions have been deleted
uses: actions/[email protected]
with:
github-token: ${{ github.token }}
Expand Down Expand Up @@ -125,16 +126,27 @@ jobs:
runs-on: "ubuntu-latest"
permissions:
packages: write
if: always()
steps:
- uses: actions/checkout@v4

- id: get-issue-number
if: ${{ github.event_name == 'pull_request' }}
uses: hoverkraft-tech/ci-github-common/actions/[email protected]

- name: Cleanup images tags
if: ${{ github.event_name == 'pull_request' }}
uses: ./actions/docker/delete-image-tags
- name: Delete test packages
uses: actions/[email protected]
with:
image: ${{ env.IMAGE }}
tag-prefix: "${{ steps.get-issue-number.outputs.issue-number }}-"
github-token: ${{ github.token }}
script: |
const packagesToDelete = ["${{ env.IMAGE }}", "${{ env.IMAGE }}/cache"];
for (const packageName of packagesToDelete) {
const packagePayload = {
package_type: 'container',
package_name: `ci-github-container/${packageName}`,
org: 'hoverkraft-tech',
};
await github.rest.packages.deletePackageForOrg(packagePayload);
}

0 comments on commit bf5c1a9

Please sign in to comment.