Skip to content

Commit 1f12855

Browse files
committed
github actions
1 parent 701bf52 commit 1f12855

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

.github/workflows/rust-docker.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Rust and Docker Workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
- main
8+
9+
jobs:
10+
cargo-test:
11+
runs-on: ubuntu-latest
12+
if: github.ref == 'refs/heads/dev'
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
16+
- name: Install Rust toolchain
17+
uses: actions-rs/toolchain@v1
18+
with:
19+
toolchain: stable
20+
override: true
21+
- name: Run cargo test
22+
uses: actions-rs/cargo@v1
23+
with:
24+
command: test
25+
26+
docker-build-push:
27+
runs-on: ubuntu-latest
28+
if: github.ref == 'refs/heads/main'
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v3
32+
- name: Set up QEMU
33+
uses: docker/setup-qemu-action@v3
34+
- name: Set up Docker Buildx
35+
uses: docker/setup-buildx-action@v3
36+
- name: Login to Docker Hub
37+
uses: docker/login-action@v3
38+
with:
39+
username: wangyucode
40+
password: ${{ secrets.DOCKERHUB_TOKEN }}
41+
- name: Extract version from Cargo.toml
42+
id: extract_version
43+
run: |
44+
version=$(awk -F= '/^version/ {print $2}' Cargo.toml | tr -d '"')
45+
echo "Version: $version"
46+
echo "::set-output name=version::$version"
47+
- name: Build and push Docker image
48+
uses: docker/build-push-action@v6
49+
with:
50+
context: .
51+
push: true
52+
tags: wangyucode/crane:latest,wangyucode/crane:${{ steps.extract_version.outputs.version }}

0 commit comments

Comments
 (0)