Skip to content

Commit

Permalink
Update PR lint workflow to post Docker image info
Browse files Browse the repository at this point in the history
-  Modify Docker build step to tag images using PR number only
-  Add a new step to retrieve Docker image information using docker inspect and jq
-  Add another step to post this Docker image information as a comment on the PR using actions/github-script
-  The image information includes the image ID, creation time, size, and tags
  • Loading branch information
jag-k committed Apr 9, 2024
1 parent e677811 commit 26c0af0
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions .github/workflows/pr_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,42 @@ jobs:
${{ runner.os }}-buildx-
- name: Build Docker image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
id: docker_image
with:
context: .
push: false
tags: user/app:pr-${{ github.event.pull_request.number }}
load: true
tags: pr-${{ github.event.pull_request.number }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
platforms: linux/amd64,linux/arm64,linux/arm/v7

- name: Get Docker image info
id: get_info
run: |
IMAGE_INFO=$(docker inspect ${{ steps.docker_image.outputs.imageid }} | jq -r '{id: .[0].Id, created: .[0].Created, size: .[0].Size, repoTags: .[0].RepoTags[0]}')
echo "info=$IMAGE_INFO" >> "$GITHUB_OUTPUT"
echo "Info: $IMAGE_INFO"
- name: Post image info to PR
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# language=JavaScript
script: |
const issue_number = context.issue.number;
const image_info = JSON.parse("${{ steps.get_info.outputs.info }}");
const message = (
`The Docker image information is as follows:\n\n`
`- ID: ${image_info.id}\n`
`- Created: ${image_info.created}\n`
`- Size: ${image_info.size}\n`
`- Tag(s): ${image_info.repoTags}\n`
);
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});

0 comments on commit 26c0af0

Please sign in to comment.