Skip to content

Commit a23bb49

Browse files
authored
feat: add Dependabot config and update CI workflows (#284)
- Introduces .github/dependabot.yml to enable monthly dependency updates for GitHub Actions. - Updates Docker and lint workflows to use pinned action versions, and improved permissions. - Updated Docker build/publish steps based on [the official guidelines](https://docs.github.com/en/actions/how-tos/use-cases-and-examples/publishing-packages/publishing-docker-images). - Also sets environment variables and minor improvements for reliability and security. (Copilot wrote this description)
1 parent d018b0c commit a23bb49

File tree

3 files changed

+82
-37
lines changed

3 files changed

+82
-37
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
# Maintain dependencies for GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "monthly"
8+
groups:
9+
actions:
10+
patterns:
11+
- "*"
Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,69 @@
1-
name: Docker
1+
name: Build and publish a Docker image
22

3-
on: [push]
3+
on: [push, pull_request, workflow_dispatch]
44

55
env:
6-
IMAGE_NAME: chiya
7-
REPOSITORY: ghcr.io
6+
REGISTRY: ghcr.io
7+
IMAGE_NAME: ${{ github.repository }}
8+
FORCE_COLOR: 1
9+
# This environment variable determines whether to push the Docker image to the registry.
10+
# It evaluates to 'true' if the workflow is NOT triggered by a pull request,
11+
# or if the pull request originates from the 'Snaacky/chiya' repository.
12+
# This prevents pushing images from forks or untrusted sources.
13+
PUSH_TO_REGISTRY: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'Snaacky/chiya' }}
814

915
jobs:
10-
push:
16+
build-and-push-image:
1117
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
packages: write
21+
id-token: write
22+
attestations: write
1223
steps:
13-
- name: Checkout repository
14-
uses: actions/checkout@v3
15-
16-
- name: Prepare metadata for build
17-
id: prep
18-
run: |
19-
VERSION=edge
20-
if [[ $GITHUB_REF == refs/tags/* ]]; then
21-
VERSION=${GITHUB_REF#refs/tags/}
22-
elif [[ $GITHUB_REF == refs/heads/* ]]; then
23-
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
24-
elif [[ $GITHUB_REF == refs/pull/* ]]; then
25-
VERSION=pr-${{ github.event.number }}
26-
fi
27-
28-
# Use Docker `latest` tag convention
29-
[ "$VERSION" == "master" ] && VERSION=latest
30-
31-
echo ::set-output name=version::${VERSION}
32-
33-
- name: Build and publish Docker image (using cache)
34-
uses: whoan/docker-build-with-cache-action@v5
24+
- name: Checkout
25+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3526
with:
36-
registry: ${{ env.REPOSITORY }}
37-
username: ${{ github.repository_owner }}
27+
persist-credentials: false
28+
29+
- name: Log in to the Container registry
30+
if: ${{ env.PUSH_TO_REGISTRY == 'true' }}
31+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
32+
with:
33+
registry: ${{ env.REGISTRY }}
34+
username: ${{ github.actor }}
3835
password: ${{ secrets.GITHUB_TOKEN }}
39-
image_name: ${{ env.IMAGE_NAME }}
40-
image_tag: ${{ steps.prep.outputs.version }}
36+
37+
- name: Extract metadata (tags, labels) for Docker
38+
id: meta
39+
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
40+
with:
41+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
42+
tags: |
43+
type=ref,event=branch
44+
type=ref,event=tag
45+
type=ref,event=pr
46+
type=sha
47+
type=raw,value=latest,enable={{is_default_branch}}
48+
49+
- name: Set up Docker Buildx
50+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
51+
52+
- name: Build and push Docker image
53+
id: push
54+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
55+
with:
56+
context: .
57+
push: ${{ env.PUSH_TO_REGISTRY == 'true' }}
58+
tags: ${{ steps.meta.outputs.tags }}
59+
labels: ${{ steps.meta.outputs.labels }}
60+
cache-from: type=gha
61+
cache-to: type=gha,mode=max
62+
63+
- name: Generate artifact attestation
64+
if: ${{ env.PUSH_TO_REGISTRY == 'true' }}
65+
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.4.0
66+
with:
67+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
68+
subject-digest: ${{ steps.push.outputs.digest }}
69+
push-to-registry: true

.github/workflows/lint.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,30 @@ defaults:
66
run:
77
shell: bash
88

9+
env:
10+
FORCE_COLOR: 1
11+
UV_LOCKED: 1
12+
913
concurrency:
1014
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
1115
cancel-in-progress: true
1216

1317
jobs:
1418
check:
1519
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
1622
steps:
1723
- name: Checkout
18-
uses: actions/checkout@v4
24+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+
with:
26+
persist-credentials: false
1927

2028
- name: Install uv
21-
id: setup-uv
22-
uses: astral-sh/setup-uv@v5
23-
with:
24-
python-version: "3.13.5"
29+
uses: astral-sh/setup-uv@bd01e18f51369d5a26f1651c3cb451d3417e3bba # v6.3.1
2530

2631
- name: Install the project
27-
run: uv sync --locked
32+
run: uv sync
2833

2934
- name: Run ruff lint
3035
run: uv run ruff check .

0 commit comments

Comments
 (0)