```console $ npx mega-linter-runner -r v8 -f cupcake +----SUMMARY----+--------------------------+---------------+-------+-------+--------+----------+--------------+ | Descriptor | Linter | Mode | Files | Fixed | Errors | Warnings | Elapsed time | +---------------+--------------------------+---------------+-------+-------+--------+----------+--------------+ | ✅ ACTION | actionlint | list_of_files | 4 | | 0 | 0 | 3.25s | | ✅ BASH | bash-exec | file | 1 | | 0 | 0 | 2.77s | | ✅ BASH | shellcheck | list_of_files | 1 | | 0 | 0 | 1.16s | | ✅ BASH | shfmt | list_of_files | 1 | 0 | 0 | 0 | 0.6s | | ⚠️ COPYPASTE | jscpd | project | n/a | | 8 | 0 | 24.82s | | ⚠️ DOCKERFILE | hadolint | list_of_files | 1 | | 4 | 0 | 6.74s | | ⚠️ JAVASCRIPT | eslint | list_of_files | 15 | 0 | 1 | 0 | 11.04s | | ✅ JSON | jsonlint | list_of_files | 7 | | 0 | 0 | 4.76s | | ✅ JSON | npm-package-json-lint | project | n/a | | 0 | 0 | 3.26s | | ✅ JSON | prettier | list_of_files | 7 | 0 | 0 | 0 | 5.08s | | ✅ JSON | v8r | list_of_files | 7 | | 0 | 0 | 47.96s | | ✅ MARKDOWN | markdownlint | list_of_files | 2 | 0 | 0 | 0 | 12.16s | | ✅ MARKDOWN | markdown-table-formatter | list_of_files | 2 | 0 | 0 | 0 | 4.15s | | ⚠️ REPOSITORY | checkov | project | n/a | | 3 | 0 | 112.11s | | ✅ REPOSITORY | gitleaks | project | n/a | | 0 | 0 | 3.09s | | ✅ REPOSITORY | git_diff | project | n/a | | 0 | 0 | 1.22s | | ✅ REPOSITORY | grype | project | n/a | | 0 | 0 | 159.7s | | ⚠️ REPOSITORY | kics | project | n/a | | 24 | 0 | 14.82s | | ✅ REPOSITORY | secretlint | project | n/a | | 0 | 0 | 7.24s | | ✅ REPOSITORY | syft | project | n/a | | 0 | 0 | 7.83s | | ⚠️ REPOSITORY | trivy | project | n/a | | 2 | 0 | 28.16s | | ✅ REPOSITORY | trufflehog | project | n/a | | 0 | 0 | 26.51s | | ⚠️ SPELL | cspell | list_of_files | 40 | | 224 | 0 | 82.25s | | ⚠️ SPELL | lychee | list_of_files | 17 | | 9 | 0 | 10.28s | | ✅ YAML | prettier | list_of_files | 8 | 1 | 0 | 0 | 9.12s | | ✅ YAML | v8r | list_of_files | 8 | | 0 | 0 | 39.07s | | ✅ YAML | yamllint | list_of_files | 8 | | 0 | 0 | 5.39s | +---------------+--------------------------+---------------+-------+-------+--------+----------+--------------+ ```
89 lines
4 KiB
YAML
89 lines
4 KiB
YAML
name: Build and push Docker image (amd64, arm64 to hub.docker.com and ghcr.io)
|
|
|
|
on:
|
|
workflow_dispatch: # allows manual trigger
|
|
push: # push on branch
|
|
branches: [main, dev]
|
|
paths: # ignore changes to .md files
|
|
- "**"
|
|
- "!*.md"
|
|
# - '!.github/**'
|
|
pull_request: # runs when opened/reopened or when the head branch is updated
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
env:
|
|
BRANCH: ${{ github.head_ref || github.ref_name }} # head_ref/base_ref are only set for PRs, for branches ref_name will be used
|
|
|
|
jobs:
|
|
docker:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
- name: Set environment variables
|
|
run: |
|
|
echo "NOW=$(date -R)" >> "$GITHUB_ENV" # date -Iseconds; date +'%Y-%m-%dT%H:%M:%S'
|
|
if [[ "$BRANCH" == "main" ]]; then
|
|
echo "IMAGE_TAG=latest" >> "$GITHUB_ENV"
|
|
else
|
|
echo "IMAGE_TAG=$BRANCH" >> "$GITHUB_ENV"
|
|
fi
|
|
- name: Extract metadata for Docker (tags, labels)
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: |
|
|
${{ secrets.DOCKERHUB_USERNAME }}/free-games-claimer
|
|
ghcr.io/${{ github.actor }}/free-games-claimer
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
# use docker tag 'latest' for the default branch (default is to only use it for the latest git tag)
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
labels: |
|
|
org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}}
|
|
env:
|
|
# otherwise labels are not shown on GitHub due to multi-arch image: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#adding-a-description-to-multi-arch-images
|
|
# https://github.com/docker/metadata-action#annotations
|
|
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@v3
|
|
# if: ${{ secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' }} # does not work: Unrecognized named-value: 'secrets' - https://www.cloudtruth.com/blog/skipping-jobs-in-github-actions-when-secrets-are-unavailable-securely-inject-configuration-secrets-into-github
|
|
if: github.event_name != 'pull_request' # don't try to login since PRs don't have access to secrets and need to set them in their fork
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }} # actor is user that opened PR, was repository_owner before
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
if: ${{ env.IMAGE_TAG != '' }}
|
|
with:
|
|
context: .
|
|
# push: ${{ github.event_name != 'pull_request' }}
|
|
push: ${{ secrets.DOCKERHUB_USERNAME != '' }} # here we can access secrets
|
|
# TODO speed up by building in parallel? https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
|
|
platforms: linux/amd64,linux/arm64
|
|
build-args: |
|
|
COMMIT=${{ github.sha }}
|
|
BRANCH=${{ env.BRANCH }}
|
|
NOW=${{ env.NOW }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
annotations: ${{ steps.meta.outputs.annotations }}
|
|
# tags: |
|
|
# ${{ secrets.DOCKERHUB_USERNAME }}/free-games-claimer:${{env.IMAGE_TAG}}
|
|
# ghcr.io/${{ github.actor }}/free-games-claimer:${{env.IMAGE_TAG}}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|