-
-
Notifications
You must be signed in to change notification settings - Fork 32
153 lines (142 loc) · 4.87 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: Rust
on:
push:
branches:
- main
tags:
- "*"
pull_request:
branches: [ main ]
jobs:
ci:
env:
RUST_BACKTRACE: 1
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- nightly
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --all --check
- run: cargo clippy --all --all-features -- -D warnings
- run: cargo test --workspace --verbose
# Code from here: https://docs.github.com/en/actions/publishing-packages/publishing-docker-images
# TODO: Add a step to publish the image to the Docker Hub
# TODO: Build multiple images for different architectures, see this: https://docs.docker.com/build/ci/github-actions/multi-platform/
# But follow this documentation would slow down the CI/CD pipeline, so it's better to use a matrix strategy
image:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
name: Build and push Docker image
if: |
github.event_name == 'push' && (
github.event.ref == 'refs/heads/main' ||
startsWith(github.event.ref, 'refs/tags/')
)
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
attestations: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=tag
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Code mutably borrowed from https://github.com/EmbarkStudios/cargo-deny/, thanks Embark!
release:
name: Release
if: startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
include:
- os: ubuntu-20.04
rust: stable
target: x86_64-unknown-linux-musl
bin: cargo-machete
- os: windows-2022
rust: stable
target: x86_64-pc-windows-msvc
bin: cargo-machete.exe
- os: macos-11
rust: stable
target: x86_64-apple-darwin
bin: cargo-machete
- os: macos-11
rust: stable
target: aarch64-apple-darwin
bin: cargo-machete
runs-on: ${{ matrix.os }}
steps:
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- name: Install musl tools
if: matrix.os == 'ubuntu-20.04'
run: |
sudo apt-get install -y musl-tools
- name: Checkout
uses: actions/checkout@v3
- name: cargo fetch
run: cargo fetch --target ${{ matrix.target }}
- name: Release build
run: cargo build --release --target ${{ matrix.target }}
- name: Package
shell: bash
run: |
name=cargo-machete
tag=$(git describe --tags --abbrev=0)
release_name="$name-$tag-${{ matrix.target }}"
release_tar="${release_name}.tar.gz"
mkdir "$release_name"
if [ "${{ matrix.target }}" != "x86_64-pc-windows-msvc" ]; then
strip "target/${{ matrix.target }}/release/${{ matrix.bin }}"
fi
cp "target/${{ matrix.target }}/release/${{ matrix.bin }}" "$release_name/"
cp README.md LICENSE.md "$release_name/"
tar czvf "$release_tar" "$release_name"
rm -r "$release_name"
# Windows environments in github actions don't have the gnu coreutils installed,
# which includes the shasum exe, so we just use powershell instead
if [ "${{ matrix.target }}" == "x86_64-pc-windows-msvc" ]; then
echo "(Get-FileHash \"${release_tar}\" -Algorithm SHA256).Hash | Out-File -Encoding ASCII -NoNewline \"${release_tar}.sha256\"" | pwsh -c -
else
echo -n "$(shasum -ba 256 "${release_tar}" | cut -d " " -f 1)" > "${release_tar}.sha256"
fi
- name: Publish
uses: softprops/action-gh-release@v1
with:
draft: true
files: "cargo-machete*"
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}