Skip to content

Commit

Permalink
ci: fix docker-publis workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogyuchi committed Dec 18, 2023
1 parent be63258 commit df3396e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
# syntax=docker/dockerfile:1.6.0@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50032edf31be0021
FROM --platform=$BUILDPLATFORM busybox:latest@sha256:5c63a9b46e7139d2d5841462859edcbbf57f238af891b6096578e5894cfe5ae2 AS env
ARG TARGETPLATFORM
ARG BINARY_NAME=rust-ci-test
RUN --mount=type=bind,source=artifact,target=artifact \
if [ "$TARGETPLATFORM" = 'darwin/amd64' ]; then\
cp artifact/x86_64-apple-darwin/"$BINARY_NAME" .\
cp artifact/x86_64-apple-darwin/binary .\
;elif [ "$TARGETPLATFORM" = 'darwin/arm64' ]; then\
cp artifact/aarch64-apple-darwin/"$BINARY_NAME" .\
cp artifact/aarch64-apple-darwin/binary .\
;elif [ "$TARGETPLATFORM" = 'linux/amd64' ]; then\
cp artifact/x86_64-unknown-linux-musl/"$BINARY_NAME" .\
cp artifact/x86_64-unknown-linux-musl/binary .\
;elif [ "$TARGETPLATFORM" = 'linux/arm64' ]; then\
cp artifact/aarch64-unknown-linux-musl/"$BINARY_NAME" .\
;elif [ "$TARGETPLATFORM" = 'windows/amd64' ]; then\
cp artifact/x86_64-pc-windows-msvc/"$BINARY_NAME".exe "$BINARY_NAME"\
cp artifact/aarch64-unknown-linux-musl/binary .\
;fi

FROM scratch
COPY --from=env --chmod=755 rust-ci-test .
ENTRYPOINT ["./rust-ci-test"]
COPY --from=env --chmod=755 binary .
ENTRYPOINT ["./binary"]
26 changes: 14 additions & 12 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
BINARY_NAME: ${{ github.event.repository.name }}

jobs:
build:
Expand Down Expand Up @@ -67,24 +68,25 @@ jobs:
uses: taiki-e/install-action@a1f180f99a1c725ceb0e42382d8aa2402edf1558 # v2.22.5
with:
tool: cross
- run: ${{ (!matrix.os && matrix.use-cross) && 'cross' || 'cargo' }} build --locked --release --target ${{ matrix.target }}
- run: mkdir dist
- run: ${{ (!matrix.os && matrix.use-cross) && 'cross' || 'cargo' }} rustc --locked --release --target=${{ matrix.target }} -- --emit=link=dist/binary
- uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0
with:
name: ${{ matrix.target }}
path: |
target/${{ matrix.target }}/release/rust-ci-test
target/${{ matrix.target }}/release/rust-ci-test.exe
target/${{ matrix.target }}/release/binary
target/${{ matrix.target }}/release/binary.exe
- name: Upload to release
if: ${{ inputs.tag-name }}
working-directory: target/${{ matrix.target }}/release/
working-directory: dist/
run: |
if [ -e rust-ci-test.exe ]; then
filename="rust-ci-test-${{ inputs.tag-name }}-${{ matrix.target }}.exe"
mv rust-ci-test.exe "$filename"
if [ -e binary.exe ]; then
filename="${{ env.BINARY_NAME }}-${{ inputs.tag-name }}-${{ matrix.target }}.exe"
mv binary.exe "$filename"
gh release upload ${{ inputs.tag-name }} "$filename"#${{ matrix.target }} --clobber
else
filename="rust-ci-test-${{ inputs.tag-name }}-${{ matrix.target }}"
mv rust-ci-test "$filename"
filename="${{ env.BINARY_NAME }}-${{ inputs.tag-name }}-${{ matrix.target }}"
mv binary "$filename"
gh release upload ${{ inputs.tag-name }} "$filename"#${{ matrix.target }} --clobber
fi
docker:
Expand All @@ -101,7 +103,7 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
sparse-checkout: |
.github/workflows/build/Dockerfile
.github/files/build/Dockerfile
sparse-checkout-cone-mode: false
- name: Download build artifact
uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 # v4.0.0
Expand All @@ -125,15 +127,15 @@ jobs:
tags: |
type=semver,pattern={{version}},value=${{ inputs.tag-name }}
type=semver,pattern={{major}}.{{minor}},value=${{ inputs.tag-name }}
type=semver,pattern={{major}},value=${{ inputs.tag-name }}
type=semver,pattern={{major}},value=${{ inputs.tag-name }},enable=${{ !(startsWith(github.ref, 'refs/tags/v0.') || startsWith(inputs.tag-name, 'v0.')) }}
type=edge
type=ref,event=branch
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
with:
context: .
file: .github/workflows/build/Dockerfile
file: .github/files/build/Dockerfile
platforms: darwin/amd64,darwin/arm64,linux/amd64,linux/arm64,windows/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
Expand Down

0 comments on commit df3396e

Please sign in to comment.