From 2abc71607f87c39c107f144fa7b284e82fb7c2b6 Mon Sep 17 00:00:00 2001 From: itchyny Date: Sat, 8 Jul 2023 10:14:16 +0900 Subject: [PATCH] Build Docker image using pre-built executables --- .github/workflows/ci.yml | 100 +++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 42 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b935fb1f1..95db6ffd8f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,7 @@ on: push: branches: - master + - improve-docker-image-build tags: - "jq-*" pull_request: @@ -13,25 +14,23 @@ jobs: fail-fast: false matrix: arch: - [ - amd64, - arm64, - armel, - armhf, - i386, - mips, - mips64, - mips64el, - mips64r6, - mips64r6el, - mipsel, - mipsr6, - mipsr6el, - powerpc, - ppc64el, - s390x, - riscv64, - ] + - amd64 + - arm64 + - armel + - armhf + - i386 + - mips + - mips64 + - mips64el + - mips64r6 + - mips64r6el + - mipsel + - mipsr6 + - mipsr6el + - powerpc + - ppc64el + - riscv64 + - s390x include: - arch: amd64 CC: "x86_64-linux-gnu" @@ -63,10 +62,10 @@ jobs: CC: "powerpc-linux-gnu" - arch: ppc64el CC: "powerpc64le-linux-gnu" - - arch: s390x - CC: "s390x-linux-gnu" - arch: riscv64 CC: "riscv64-linux-gnu" + - arch: s390x + CC: "s390x-linux-gnu" runs-on: ubuntu-22.04 env: AR: ${{ matrix.CC }}-ar @@ -118,7 +117,7 @@ jobs: - name: Upload Artifacts uses: actions/upload-artifact@v3 with: - name: jq-${{ env.SUFFIX }} + name: jq-linux path: jq-${{ env.SUFFIX }} if-no-files-found: error retention-days: 7 @@ -128,10 +127,8 @@ jobs: fail-fast: false matrix: arch: - [ - amd64, - arm64, - ] + - amd64 + - arm64 include: - arch: amd64 target: "x86_64-apple-darwin" @@ -151,7 +148,7 @@ jobs: # brew update sometimes fails with "Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask failed!" brew update || brew update-reset brew install autoconf automake libtool - - name: "Set CC" + - name: Set CC run: | echo "CC=clang -target ${{ matrix.target }}$(uname -r)" >> $GITHUB_ENV - name: Build @@ -186,7 +183,7 @@ jobs: - name: Upload Artifacts uses: actions/upload-artifact@v3 with: - name: jq-${{ env.SUFFIX }} + name: jq-macos path: jq-${{ env.SUFFIX }} if-no-files-found: error retention-days: 7 @@ -196,10 +193,8 @@ jobs: fail-fast: false matrix: arch: - [ - amd64, - i386, - ] + - amd64 + - i386 include: - arch: amd64 CC: "x86_64-pc-msys" @@ -266,7 +261,7 @@ jobs: - name: Upload Artifacts uses: actions/upload-artifact@v3 with: - name: jq-${{ env.SUFFIX }} + name: jq-windows path: jq-${{ env.SUFFIX }}.exe if-no-files-found: error retention-days: 7 @@ -307,18 +302,42 @@ jobs: runs-on: ubuntu-latest permissions: packages: write - if: startsWith(github.ref, 'refs/tags/jq-') + needs: linux + # if: startsWith(github.ref, 'refs/tags/jq-') steps: - name: Clone repository uses: actions/checkout@v3 + - name: Download executables + uses: actions/download-artifact@v3 with: - submodules: true + name: jq-linux + - name: Move executables + run: | + ls -al + mkdir -p linux/{386,amd64,arm64,mips64le,ppc64le,riscv64,s390x} + mv jq-linux-i386 linux/386/jq + mv jq-linux-amd64 linux/amd64/jq + mv jq-linux-arm64 linux/arm64/jq + mv jq-linux-mips64el linux/mips64le/jq + mv jq-linux-ppc64el linux/ppc64le/jq + mv jq-linux-riscv64 linux/riscv64/jq + mv jq-linux-s390x linux/s390x/jq + chmod +x linux/*/jq + - name: Create Dockerfile + run: | + cat <<'EOF' >Dockerfile + FROM scratch + ARG TARGETPLATFORM + COPY AUTHORS COPYING $TARGETPLATFORM/jq / + RUN ["/jq", "--version"] + ENTRYPOINT ["/jq"] + EOF - name: Docker metadata uses: docker/metadata-action@v4 id: metadata with: images: ghcr.io/${{ github.repository }} - tags: type=match,pattern=jq-(.*),group=1,value=${{ github.ref_name }} + tags: latest # type=match,pattern=jq-(.*),group=1,value=${{ github.ref_name }} - name: Set up QEMU uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx @@ -335,7 +354,7 @@ jobs: context: . push: true provenance: false - platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x + platforms: linux/386,linux/amd64,linux/arm64,linux/mips64le,linux/ppc64le,linux/riscv64,linux/s390x tags: ${{ steps.metadata.outputs.tags }} labels: ${{ steps.metadata.outputs.labels }} @@ -355,10 +374,7 @@ jobs: TAG_NAME: ${{ github.ref_name }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - mkdir -p "release" - for files in jq-*; do - cp -rf "${files}/"* "release/" - done - + mkdir -p release + mv jq-*/* release/ gh release create "$TAG_NAME" --draft --title "jq ${TAG_NAME#jq-}" --generate-notes gh release upload "$TAG_NAME" --clobber release/jq-*