ci: update workflow config

This commit is contained in:
sebthom
2024-12-27 12:54:21 +01:00
parent cde3250ab8
commit 7b579900c3
3 changed files with 67 additions and 25 deletions

View File

@@ -6,12 +6,12 @@ updates:
schedule: schedule:
interval: weekly interval: weekly
day: monday day: monday
time: "17:00" time: "14:00"
commit-message: commit-message:
prefix: ci prefix: ci
prefix-development: ci prefix-development: ci
include: scope include: scope
labels: labels:
- pinned
- dependencies - dependencies
- gha - gha
- pinned

View File

@@ -1,11 +1,13 @@
# SPDX-FileCopyrightText: © Sebastian Thomschke and contributors # SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
# SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/ # SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot
# #
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
name: Build name: Build
on: on:
schedule:
- cron: '0 15 1 * *'
push: push:
branches-ignore: # build all branches except: branches-ignore: # build all branches except:
- 'dependabot/**' # prevent GHA triggered twice (once for commit to the branch and once for opening/syncing the PR) - 'dependabot/**' # prevent GHA triggered twice (once for commit to the branch and once for opening/syncing the PR)
@@ -94,7 +96,6 @@ jobs:
- name: Git Checkout - name: Git Checkout
uses: actions/checkout@v4 # https://github.com/actions/checkout uses: actions/checkout@v4 # https://github.com/actions/checkout
- name: "Install: Chromium Browser" - name: "Install: Chromium Browser"
if: env.ACT == 'true' && startsWith(matrix.os, 'ubuntu') if: env.ACT == 'true' && startsWith(matrix.os, 'ubuntu')
run: | run: |
@@ -217,7 +218,7 @@ jobs:
- name: Upload self-contained executable - name: Upload self-contained executable
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
if: ${{ github.ref_name == 'main' && matrix.PUBLISH_RELEASE && !env.ACT }} if: github.ref_name == 'main' && matrix.PUBLISH_RELEASE && !env.ACT
with: with:
name: artifacts-${{ matrix.os }} name: artifacts-${{ matrix.os }}
path: dist/kleinanzeigen-bot* path: dist/kleinanzeigen-bot*
@@ -234,7 +235,7 @@ jobs:
- name: Publish Docker image - name: Publish Docker image
if: ${{ github.repository_owner == 'Second-Hand-Friends' && github.ref_name == 'main' && matrix.PUBLISH_RELEASE && startsWith(matrix.os, 'ubuntu') && !env.ACT }} if: github.repository_owner == 'Second-Hand-Friends' && github.ref_name == 'main' && matrix.PUBLISH_RELEASE && startsWith(matrix.os, 'ubuntu') && !env.ACT
run: | run: |
set -eux set -eux
@@ -251,8 +252,8 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: needs:
- build - build
if: ${{ github.ref_name == 'main' && !github.event.act }} if: (github.ref_name == 'main' || github.ref_name == 'release') && !github.event.act
concurrency: publish-latest-release # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idconcurrency concurrency: publish-${{ github.ref_name }}-release # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idconcurrency
steps: steps:
- name: "Show: GitHub context" - name: "Show: GitHub context"
@@ -261,7 +262,7 @@ jobs:
run: echo $GITHUB_CONTEXT run: echo $GITHUB_CONTEXT
- name: Show environment variables - name: "Show: environment variables"
run: env | sort run: env | sort
@@ -269,7 +270,7 @@ jobs:
uses: vegardit/fast-apt-mirror.sh@v1 uses: vegardit/fast-apt-mirror.sh@v1
- name: Git checkout - name: Git Checkout
# only required by "gh release create" to prevent "fatal: Not a git repository" # only required by "gh release create" to prevent "fatal: Not a git repository"
uses: actions/checkout@v4 # https://github.com/actions/checkout uses: actions/checkout@v4 # https://github.com/actions/checkout
@@ -309,27 +310,40 @@ jobs:
run: clamscan kleinanzeigen-* run: clamscan kleinanzeigen-*
- name: "Delete previous 'latest' release" - name: "Determine release name"
id: release
run: |
case "$GITHUB_REF_NAME" in
main)
echo "name=preview" >>"$GITHUB_OUTPUT"
;;
release)
echo "name=latest" >>"$GITHUB_OUTPUT"
;;
esac
- name: "Delete previous '${{ steps.release.outputs.name }}' release"
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NAME: latest RELEASE_NAME: ${{ steps.release.outputs.name }}
# https://cli.github.com/manual/gh_release_delete # https://cli.github.com/manual/gh_release_delete
run: | run: |
GH_DEBUG=1 gh release delete "$RELEASE_NAME" --yes --cleanup-tag || true GH_DEBUG=1 gh release delete "$RELEASE_NAME" --yes --cleanup-tag || true
- name: "Create 'latest' release" - name: "Create '${{ steps.release.outputs.name }}' Release"
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NAME: latest RELEASE_NAME: ${{ steps.release.outputs.name }}
run: | COMMIT_MSG: ${{ github.event.head_commit.message }} # https://stackoverflow.com/a/78420438/5116073
set -eux
# https://cli.github.com/manual/gh_release_create # https://cli.github.com/manual/gh_release_create
run: |
GH_DEBUG=1 gh release create "$RELEASE_NAME" \ GH_DEBUG=1 gh release create "$RELEASE_NAME" \
--title "$RELEASE_NAME" \ --title "$RELEASE_NAME" \
--latest \ ${{ steps.release.outputs.name == 'latest' && '--latest' || '' }} \
--notes ${{ toJSON(github.event.head_commit.message) }} \ ${{ steps.release.outputs.name == 'preview' && '--prerelease' || '' }} \
--notes "$COMMIT_MSG" \
--target "${{ github.sha }}" \ --target "${{ github.sha }}" \
kleinanzeigen-bot-darwin-amd64 \ kleinanzeigen-bot-darwin-amd64 \
kleinanzeigen-bot-darwin-arm64 \ kleinanzeigen-bot-darwin-arm64 \
@@ -343,3 +357,25 @@ jobs:
with: with:
name: "*" name: "*"
failOnError: false failOnError: false
###########################################################
dependabot-pr-auto-merge:
###########################################################
needs: build
if: github.event_name == 'pull_request' && github.actor == 'dependabot[bot]'
runs-on: ubuntu-latest
concurrency: dependabot-pr-auto-merge
permissions:
contents: write
pull-requests: write
steps:
- name: Merge Dependabot PR
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
PR_URL: ${{github.event.pull_request.html_url}}
run: |
gh pr merge --auto --rebase "$PR_URL"

View File

@@ -84,10 +84,16 @@ jobs:
if git diff --exit-code pdm.lock; then if git diff --exit-code pdm.lock; then
echo "updates=" >> "$GITHUB_OUTPUT" echo "updates=" >> "$GITHUB_OUTPUT"
else else
updates="$(echo "$updates" | grep Update | grep -v kleinanzeigen-bot)"
if [[ $(wc -l <<< "$updates") -eq 1 ]]; then
echo "title=$(echo "$updates" | head -n 1)" >> "${GITHUB_OUTPUT}"
else
echo "title=Update Python dependencies" >> "${GITHUB_OUTPUT}"
fi
# https://github.com/orgs/community/discussions/26288#discussioncomment-3876281 # https://github.com/orgs/community/discussions/26288#discussioncomment-3876281
delimiter="$(openssl rand -hex 8)" delimiter="$(openssl rand -hex 8)"
echo "updates<<${delimiter}" >> "${GITHUB_OUTPUT}" echo "updates<<${delimiter}" >> "${GITHUB_OUTPUT}"
echo "$(echo "$updates" | grep Update | grep -v kleinanzeigen-bot)" >> "${GITHUB_OUTPUT}" echo "$updates" >> "${GITHUB_OUTPUT}"
echo "${delimiter}" >> "${GITHUB_OUTPUT}" echo "${delimiter}" >> "${GITHUB_OUTPUT}"
fi fi
@@ -96,7 +102,7 @@ jobs:
uses: peter-evans/create-pull-request@v7 # https://github.com/peter-evans/create-pull-request uses: peter-evans/create-pull-request@v7 # https://github.com/peter-evans/create-pull-request
if: "${{ steps.update_deps.outputs.updates != '' }}" if: "${{ steps.update_deps.outputs.updates != '' }}"
with: with:
title: "chore: Update Python dependencies" title: "chore: ${{ steps.update_deps.outputs.title }}"
author: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" author: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
committer: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" committer: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
commit-message: "chore: Update Python dependencies" commit-message: "chore: Update Python dependencies"