Update tj-actions/changed-files action to v40.2.1 #326
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and push docker image | |
on: | |
push: | |
tags: ['*'] | |
branches: ["dev"] | |
paths-ignore: | |
- README.md | |
- LICENSE | |
- .github/workflows/update-dockerhub-desc.yml | |
- .github/workflows/test-pr.yml | |
env: | |
IMAGE_REGISTRY: ${{ vars.REGISTRY_PUBLIC }} | |
#<account>/<repo> | |
IMAGE_NAME: ${{ github.repository }} | |
TEST_TAG: test-build | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Prepare | |
id: prepare | |
run: | | |
DOCKER_PLATFORMS=${{ vars.CONTAINER_ARCH }} | |
VERSION=${GITHUB_REF#refs/*/} | |
TAGS="${{ env.IMAGE_NAME }}:${VERSION}" | |
if [[ $GITHUB_REF == refs/tags/* ]]; then | |
TAGS="$TAGS,${{ env.IMAGE_NAME }}:latest" | |
fi | |
for TAG in $(echo $TAGS | sed 's/,/ /g'); do | |
TAGS="$TAGS,quay.io/$TAG" | |
done | |
echo "platforms=${DOCKER_PLATFORMS}" >> $GITHUB_OUTPUT | |
echo "tags=${TAGS}" >> $GITHUB_OUTPUT | |
- name: Set up QEMU | |
id: qemu | |
uses: docker/setup-qemu-action@v3 | |
with: | |
image: tonistiigi/binfmt:latest | |
platforms: all | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
id: buildx | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.IMAGE_REGISTRY }} | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to Quay.io | |
uses: docker/login-action@v3 | |
with: | |
registry: quay.io | |
username: ${{ secrets.QUAYIO_USERNAME }} | |
password: ${{ secrets.QUAYIO_TOKEN }} | |
- name: Build and Test | |
run: | | |
export TEST_IMAGE_NAME=${{ env.IMAGE_NAME }}:${{ env.TEST_TAG }} | |
docker compose --file docker-compose.test.yml up --exit-code-from sut -t 10 --build | |
- name: Run Trivy vulnerability scanner | |
uses: aquasecurity/[email protected] | |
with: | |
image-ref: 'docker.io/${{ env.IMAGE_NAME }}:${{ env.TEST_TAG }}' | |
format: 'sarif' | |
output: 'trivy-results.sarif' | |
severity: 'CRITICAL,HIGH' | |
exit-code: 0 | |
- name: Upload Trivy scan results to GitHub Security tab | |
uses: github/codeql-action/upload-sarif@v2 | |
with: | |
sarif_file: 'trivy-results.sarif' | |
- name: Run the Anchore scan action | |
uses: anchore/scan-action@v3 | |
id: anchore-scan | |
with: | |
image: 'docker.io/${{ env.IMAGE_NAME }}:${{ env.TEST_TAG }}' | |
output-format: sarif | |
fail-build: false | |
- name: Upload Anchore Scan Report | |
uses: github/codeql-action/upload-sarif@v2 | |
with: | |
sarif_file: ${{ steps.anchore-scan.outputs.sarif }} | |
- name: Get changed container files | |
id: changed-files | |
uses: tj-actions/[email protected] | |
with: | |
files: | | |
rootfs/** | |
Dockerfile | |
- name: List changed container files | |
run: | | |
echo "Any container files changed? ${{ steps.changed-files.outputs.any_changed }}" | |
echo "Changed files: ${{ steps.changed-files.outputs.all_changed_files }}" | |
- name: Build and push | |
if: steps.changed-files.outputs.any_changed == 'true' | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.prepare.outputs.tags }} | |
platforms: ${{ steps.prepare.outputs.platforms }} | |
provenance: false |