diff --git a/.github/workflows/build/Dockerfile b/.github/files/build/Dockerfile similarity index 53% rename from .github/workflows/build/Dockerfile rename to .github/files/build/Dockerfile index 1606359b8..2d05a316d 100644 --- a/.github/workflows/build/Dockerfile +++ b/.github/files/build/Dockerfile @@ -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"] diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 290b5020b..a32e32605 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -18,6 +18,7 @@ on: env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} + BINARY_NAME: ${{ github.event.repository.name }} jobs: build: @@ -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 + dist/binary + dist/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: @@ -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 @@ -125,7 +127,7 @@ 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 @@ -133,8 +135,8 @@ jobs: uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0 with: context: . - file: .github/workflows/build/Dockerfile - platforms: darwin/amd64,darwin/arm64,linux/amd64,linux/arm64,windows/amd64 + file: .github/files/build/Dockerfile + platforms: darwin/amd64,darwin/arm64,linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}