Skip to content

Commit 432476e

Browse files
committed
add github actions workflow
1 parent 2c8f129 commit 432476e

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Docker Image Build
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
pull_request:
7+
branches: ["main"]
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
checks:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repo
18+
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
19+
20+
- name: Set up Rust toolchain
21+
uses: actions-rust-lang/setup-rust-toolchain@11df97af8e8102fd60b60a77dfbf58d40cd843b8
22+
with:
23+
toolchain: nightly-2024-10-17
24+
components: rustfmt, clippy
25+
26+
- name: Check formatting
27+
run: cargo fmt --all -- --check
28+
29+
- name: Run clippy
30+
run: cargo clippy -- -D warnings
31+
32+
build-and-push:
33+
permissions:
34+
contents: read
35+
packages: write
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout repo
39+
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
40+
41+
# Set image tag to git tag, or commit hash for pull request
42+
- name: Set IMAGE_TAG
43+
run: |
44+
if [ "${{ github.event_name }}" == "push" ]; then
45+
echo "IMAGE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
46+
else
47+
echo "IMAGE_TAG=${{ github.sha }}" >> $GITHUB_ENV
48+
fi
49+
50+
- name: Log in to the Container registry
51+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
52+
with:
53+
registry: ${{ env.REGISTRY }}
54+
username: ${{ github.actor }}
55+
password: ${{ secrets.GITHUB_TOKEN }}
56+
57+
- name: Extract metadata (tags, labels) for Docker
58+
id: meta
59+
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
60+
with:
61+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
62+
tags: |
63+
type=raw,value=${{ env.IMAGE_TAG }}
64+
type=raw,value=${{ github.sha }}
65+
type=raw,value=latest
66+
67+
- name: Build and push Docker image
68+
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75
69+
with:
70+
context: .
71+
push: true
72+
tags: ${{ steps.meta.outputs.tags }}
73+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)