Skip to content

Commit 4cb1472

Browse files
committed
ci: fix docker-publis workflow
1 parent be63258 commit 4cb1472

2 files changed

Lines changed: 20 additions & 21 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
# syntax=docker/dockerfile:1.6.0@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50032edf31be0021
22
FROM --platform=$BUILDPLATFORM busybox:latest@sha256:5c63a9b46e7139d2d5841462859edcbbf57f238af891b6096578e5894cfe5ae2 AS env
33
ARG TARGETPLATFORM
4-
ARG BINARY_NAME=rust-ci-test
54
RUN --mount=type=bind,source=artifact,target=artifact \
65
if [ "$TARGETPLATFORM" = 'darwin/amd64' ]; then\
7-
cp artifact/x86_64-apple-darwin/"$BINARY_NAME" .\
6+
cp artifact/x86_64-apple-darwin/binary .\
87
;elif [ "$TARGETPLATFORM" = 'darwin/arm64' ]; then\
9-
cp artifact/aarch64-apple-darwin/"$BINARY_NAME" .\
8+
cp artifact/aarch64-apple-darwin/binary .\
109
;elif [ "$TARGETPLATFORM" = 'linux/amd64' ]; then\
11-
cp artifact/x86_64-unknown-linux-musl/"$BINARY_NAME" .\
10+
cp artifact/x86_64-unknown-linux-musl/binary .\
1211
;elif [ "$TARGETPLATFORM" = 'linux/arm64' ]; then\
13-
cp artifact/aarch64-unknown-linux-musl/"$BINARY_NAME" .\
14-
;elif [ "$TARGETPLATFORM" = 'windows/amd64' ]; then\
15-
cp artifact/x86_64-pc-windows-msvc/"$BINARY_NAME".exe "$BINARY_NAME"\
12+
cp artifact/aarch64-unknown-linux-musl/binary .\
1613
;fi
1714

1815
FROM scratch
19-
COPY --from=env --chmod=755 rust-ci-test .
20-
ENTRYPOINT ["./rust-ci-test"]
16+
COPY --from=env --chmod=755 binary .
17+
ENTRYPOINT ["./binary"]

.github/workflows/docker-publish.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ on:
1818
env:
1919
REGISTRY: ghcr.io
2020
IMAGE_NAME: ${{ github.repository }}
21+
BINARY_NAME: ${{ github.event.repository.name }}
2122

2223
jobs:
2324
build:
@@ -67,24 +68,25 @@ jobs:
6768
uses: taiki-e/install-action@a1f180f99a1c725ceb0e42382d8aa2402edf1558 # v2.22.5
6869
with:
6970
tool: cross
70-
- run: ${{ (!matrix.os && matrix.use-cross) && 'cross' || 'cargo' }} build --locked --release --target ${{ matrix.target }}
71+
- run: mkdir dist
72+
- run: ${{ (!matrix.os && matrix.use-cross) && 'cross' || 'cargo' }} rustc --locked --release --target=${{ matrix.target }} -- --emit=link=dist/binary
7173
- uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0
7274
with:
7375
name: ${{ matrix.target }}
7476
path: |
75-
target/${{ matrix.target }}/release/rust-ci-test
76-
target/${{ matrix.target }}/release/rust-ci-test.exe
77+
dist/binary
78+
dist/binary.exe
7779
- name: Upload to release
7880
if: ${{ inputs.tag-name }}
79-
working-directory: target/${{ matrix.target }}/release/
81+
working-directory: dist/
8082
run: |
81-
if [ -e rust-ci-test.exe ]; then
82-
filename="rust-ci-test-${{ inputs.tag-name }}-${{ matrix.target }}.exe"
83-
mv rust-ci-test.exe "$filename"
83+
if [ -e binary.exe ]; then
84+
filename="${{ env.BINARY_NAME }}-${{ inputs.tag-name }}-${{ matrix.target }}.exe"
85+
mv binary.exe "$filename"
8486
gh release upload ${{ inputs.tag-name }} "$filename"#${{ matrix.target }} --clobber
8587
else
86-
filename="rust-ci-test-${{ inputs.tag-name }}-${{ matrix.target }}"
87-
mv rust-ci-test "$filename"
88+
filename="${{ env.BINARY_NAME }}-${{ inputs.tag-name }}-${{ matrix.target }}"
89+
mv binary "$filename"
8890
gh release upload ${{ inputs.tag-name }} "$filename"#${{ matrix.target }} --clobber
8991
fi
9092
docker:
@@ -101,7 +103,7 @@ jobs:
101103
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
102104
with:
103105
sparse-checkout: |
104-
.github/workflows/build/Dockerfile
106+
.github/files/build/Dockerfile
105107
sparse-checkout-cone-mode: false
106108
- name: Download build artifact
107109
uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 # v4.0.0
@@ -125,15 +127,15 @@ jobs:
125127
tags: |
126128
type=semver,pattern={{version}},value=${{ inputs.tag-name }}
127129
type=semver,pattern={{major}}.{{minor}},value=${{ inputs.tag-name }}
128-
type=semver,pattern={{major}},value=${{ inputs.tag-name }}
130+
type=semver,pattern={{major}},value=${{ inputs.tag-name }},enable=${{ !(startsWith(github.ref, 'refs/tags/v0.') || startsWith(inputs.tag-name, 'v0.')) }}
129131
type=edge
130132
type=ref,event=branch
131133
type=sha
132134
- name: Build and push Docker image
133135
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
134136
with:
135137
context: .
136-
file: .github/workflows/build/Dockerfile
138+
file: .github/files/build/Dockerfile
137139
platforms: darwin/amd64,darwin/arm64,linux/amd64,linux/arm64,windows/amd64
138140
push: ${{ github.event_name != 'pull_request' }}
139141
tags: ${{ steps.meta.outputs.tags }}

0 commit comments

Comments
 (0)