Skip to content

Commit

Permalink
ci(actions/docker/delete-image-tags): fix concurrent tests issue
Browse files Browse the repository at this point in the history
  • Loading branch information
neilime committed Oct 30, 2023
1 parent 91d7d6c commit 4927b1f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions .github/workflows/__test-action-docker-delete-image-tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ on:

env:
IMAGE: "test-delete-image-tags"
TAG: "1.0.1"

jobs:
setup:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.generate-tag.outputs.tag }}
steps:
- run: |
if [ -z "${{ secrets.GITHUB_TOKEN }}" ]; then
echo "GitHub token secrets is not set"
exit 1
fi
- id: generate-tag
run: |
RC="-rc.$RANDOM"
TAG="$(printf '%d.%d.%d%s' $((1+RANDOM%20)) $((1+RANDOM%20)) $((1+RANDOM%20)) "$RC")"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
arrange:
needs: setup
uses: ./.github/workflows/docker-build-images.yml
Expand All @@ -32,14 +39,14 @@ jobs:
"build-args": { "PROD_MODE": "true" },
"target": "prod",
"platforms": ["linux/amd64"],
"tag": "1.0.1"
"tag": "${{ needs.setup.outputs.tag }}"
}
]
act-and-assert:
name: Test for "delete-image-tags" action
runs-on: ubuntu-latest
needs: arrange
needs: [setup, arrange]
permissions:
contents: read
packages: write
Expand All @@ -50,7 +57,7 @@ jobs:
uses: ./actions/docker/delete-image-tags
with:
image: ${{ env.IMAGE }}
tag-prefix: ${{ env.TAG }}
tag-prefix: ${{ needs.setup.outputs.tag }}

- name: Check ouputs
uses: actions/github-script@v6.4.1
Expand All @@ -70,7 +77,7 @@ jobs:
}
assert(Array.isArray(deletedImageTags), `"deleted-image-tags" output is not an array`);
assert.deepEqual(deletedImageTags, ["${{ env.TAG }}"]);
assert.deepEqual(deletedImageTags, ["${{ needs.setup.outputs.tag }}"]);
- name: Ensure packages have been deleted
uses: actions/github-script@v6.4.1
Expand All @@ -90,7 +97,7 @@ jobs:
const packageVersionExists = packageVersions.some(
(packageVersion) => packageVersion.metadata.container.tags.some(
(tag) => tag === "${{ env.TAG }}"
(tag) => tag === "${{ needs.setup.outputs.tag }}"
)
);
assert.equal(packageVersionExists, false, `Package version "${{ env.TAG }}" has not been deleted`);
assert.equal(packageVersionExists, false, `Package version "${{ needs.setup.outputs.tag }}" has not been deleted`);

0 comments on commit 4927b1f

Please sign in to comment.