Skip to content

ci(dependabot): enable auto-merge workflow #1295

ci(dependabot): enable auto-merge workflow

ci(dependabot): enable auto-merge workflow #1295

Workflow file for this run

# SPDX-FileCopyrightText: © Vegard IT GmbH (https://vegardit.com)

Check failure on line 1 in .github/workflows/build.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/build.yml

Invalid workflow file

(Line: 189, Col: 5): 'permissions' is already defined, (Line: 193, Col: 5): 'uses' is already defined, (Line: 194, Col: 5): 'with' is already defined
# SPDX-FileContributor: Sebastian Thomschke
# SPDX-License-Identifier: Apache-2.0
# SPDX-ArtifactOfProjectHomePage: https://github.com/vegardit/docker-meshcentral
#
# https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax
name: Build
on: # https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows
schedule:
# https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#schedule
- cron: '0 17 * * 3'
push:
branches-ignore: # build all branches except:
- 'dependabot/**' # prevent GHA triggered twice (once for commit to the branch and once for opening/syncing the PR)
tags-ignore: # don't build tags
- '**'
paths-ignore:
- '**/*.md'
- '.editorconfig'
- '.git*'
- '.github/*.yml'
- '.github/workflows/stale.yml'
pull_request:
paths-ignore:
- '**/*.md'
- '.editorconfig'
- '.git*'
- '.github/*.yml'
- '.github/workflows/stale.yml'
workflow_dispatch:
# https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#workflow_dispatch
defaults:
run:
shell: bash
env:
DOCKER_REPO_NAME: meshcentral
DOCKER_AUDIT_IMAGE: 0
TRIVY_CACHE_DIR: ~/.trivy/cache
permissions:
contents: read
jobs:
###########################################################
build:
###########################################################
runs-on: ubuntu-latest # https://github.com/actions/runner-images#available-images
timeout-minutes: 10
permissions:
packages: write
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: "Show: GitHub context"
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: printf '%s' "$GITHUB_CONTEXT" | python -m json.tool
- name: "Show: environment variables"
run: env | sort
- name: "Show: Bash version"
run: bash --version
- name: Git Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Run the sh-checker
uses: luizm/action-sh-checker@883217215b11c1fabbf00eb1a9a041f62d74c744 # master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SHFMT_OPTS: --simplify --keep-padding
with:
sh_checker_comment: true
sh_checker_checkbashisms_enable: true
sh_checker_shfmt_disable: true
- name: Check Dockerfile
uses: hadolint/hadolint-action@2a66e89f53d0771bb131a7fa31f3136336094aa6 # v3.4.0
with:
dockerfile: image/Dockerfile
- name: Cache trivy cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ env.TRIVY_CACHE_DIR }}
# https://github.com/actions/cache/issues/342#issuecomment-673371329
key: ${{ runner.os }}-trivy-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-trivy-
- name: Configure fast APT repository mirror
uses: vegardit/fast-apt-mirror.sh@806c59276adfff2df420124ad5e4587f018c358a # v1
- name: Install dos2unix
run: sudo apt-get install --no-install-recommends -y dos2unix
- name: "Determine if docker images shall be published"
id: docker_push_actions
run: |
# ACT -> https://nektosact.com/usage/index.html#skipping-steps
set -x
if [[ $GITHUB_REF_NAME == 'main' && $GITHUB_EVENT_NAME != 'pull_request' && -z "$ACT" ]]; then
echo "DOCKER_PUSH_GHCR=true" >> "$GITHUB_ENV"
echo "DOCKER_PUSH_GHCR=true" >> $GITHUB_OUTPUT
if [[ -n "${{ secrets.DOCKER_HUB_USERNAME }}" ]]; then
echo "DOCKER_PUSH=true" >> "$GITHUB_ENV"
fi
fi
- name: Login to docker.io
if: ${{ env.DOCKER_PUSH }}
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Login to ghcr.io
if: ${{ env.DOCKER_PUSH_GHCR }}
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build docker image
env:
DOCKER_BASE_IMAGE: ghcr.io/dockerhub-mirror/node:lts-slim
DOCKER_IMAGE_REPO: ${{ github.repository_owner }}/${{ env.DOCKER_REPO_NAME }}
TRIVY_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bash build-image.sh
outputs:
DOCKER_PUSH_GHCR: ${{ steps.docker_push_actions.outputs.DOCKER_PUSH_GHCR }}
###########################################################
dependabot-pr-auto-merge:
###########################################################
needs: build
# Check both the actor and PR author so this write-capable job only runs for Dependabot updates.
if: >-
needs.build.result == 'success' &&
github.actor == 'dependabot[bot]' &&
github.event_name == 'pull_request' &&
github.event.pull_request.user.login == 'dependabot[bot]'
permissions:
contents: write
pull-requests: write
uses: sebthom/gha-shared/.github/workflows/reusable.dependabot-auto-merge.yml@v1
# All inputs are optional. These values restrict merges to GitHub Actions updates.
with:
package-ecosystems: '["github-actions"]'
merge-method: squash
merge-major-updates: false
# Optional permission-complete path for concurrent workflow-file updates:
# github-app-client-id: ${{ vars.DEPENDABOT_MERGE_GITHUB_APP_CLIENT_ID }}
# Omit this block when using the built-in github.token.
# secrets:
# DEPENDABOT_MERGE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.DEPENDABOT_MERGE_GITHUB_APP_PRIVATE_KEY }}
permissions:
contents: write
pull-requests: write
uses: sebthom/gha-shared/.github/workflows/reusable.dependabot-auto-merge.yml@v1
with:
package-ecosystems: '["github-actions"]'
merge-major-updates: true
###########################################################
delete-untagged-images:
###########################################################
runs-on: ubuntu-latest # https://github.com/actions/runner-images#available-images
timeout-minutes: 5
needs: [build]
if: ${{ needs.build.outputs.DOCKER_PUSH_GHCR }}
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
permissions:
packages: write
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: Delete untagged images
uses: dataaxiom/ghcr-cleanup-action@d52806a0dc70b430571a37da1fde39733ffd640f # v1.2.2
with:
package: ${{ env.DOCKER_REPO_NAME }}
delete-untagged: true
delete-partial-images: true
delete-ghost-images: true
delete-orphaned-images: true
validate: true