From 7cecacb9952fb1cfcc666afca327861639f05ef7 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Mon, 25 Dec 2023 19:21:05 +0800 Subject: [PATCH] chore(ci): publish binary to repo.databend.rs (#319) --- .github/actions/publish_binary/action.yml | 56 +++++++++++++++++++++++ .github/workflows/release.yml | 42 ++++++++--------- 2 files changed, 76 insertions(+), 22 deletions(-) create mode 100644 .github/actions/publish_binary/action.yml diff --git a/.github/actions/publish_binary/action.yml b/.github/actions/publish_binary/action.yml new file mode 100644 index 000000000000..8add9c1846d1 --- /dev/null +++ b/.github/actions/publish_binary/action.yml @@ -0,0 +1,56 @@ +name: 'Publish Binary' +description: 'Publish Binary to GitHub Releases and Cloudflare R2' +inputs: + os: + description: "Operating system" + required: true + target: + description: "Release target" + required: true + version: + description: "Release version" + required: true +runs: + using: "composite" + steps: + + - name: Pack binary + id: package + shell: bash + run: | + mkdir -p dist + case ${{ inputs.os }} in + linux) + tar -czf dist/bendsql-${{ inputs.target }}.tar.gz -C target/${{ inputs.target }}/release bendsql + echo "file=bendsql-${{ inputs.target }}.tar.gz" >> $GITHUB_OUTPUT + ;; + macos) + tar -czf dist/bendsql-${{ inputs.target }}.tar.gz -C target/${{ inputs.target }}/release bendsql + echo "file=bendsql-${{ inputs.target }}.tar.gz" >> $GITHUB_OUTPUT + ;; + windows) + 7z a -tzip dist/bendsql-${{ inputs.target }}.zip target/${{ inputs.target }}/release/bendsql.exe + echo "file=bendsql-${{ inputs.target }}.zip" >> $GITHUB_OUTPUT + ;; + *) + echo "Unsupported OS: ${{ inputs.os }}" + exit 1 + ;; + esac + + - name: Publish to Github Releases + id: name + shell: bash + run: | + gh release upload ${{ inputs.version }} dist/${{ steps.package.outputs.file }} --clobber + + - name: Upload package to Cloudflare R2 + id: upload + shell: bash + run: | + aws s3 cp dist/${{ steps.name.outputs.file }} s3://repo/bendsql/${{ inputs.version }}/${{ steps.name.outputs.file }} --no-progress + gh api /repos/datafuselabs/bendsql/tags > tags.json + aws s3 cp ./tags.json s3://repo/bendsql/tags.json + gh api /repos/datafuselabs/bendsql/releases > releases.json + cat releases.json + aws s3 cp ./releases.json s3://repo/bendsql/releases.json diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3cbd64533ae7..96787d0f19f9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,14 +32,18 @@ jobs: shell: bash run: | cross build --release --target=${{ matrix.target }} --bin=bendsql - - name: Publish - shell: bash + - name: Publish Binary + uses: ./.github/actions/publish_binary env: GH_TOKEN: ${{ github.token }} - run: | - mkdir -p dist - tar -czf dist/bendsql-${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release bendsql - gh release upload ${{ github.ref_name }} dist/bendsql-${{ matrix.target }}.tar.gz --clobber + AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: auto + AWS_ENDPOINT_URL: ${{ secrets.R2_ENDPOINT_URL }} + with: + os: linux + target: ${{ matrix.target }} + version: ${{ github.ref_name }} build_other: name: build ${{ matrix.target }} @@ -61,24 +65,18 @@ jobs: shell: bash run: | cargo build --release --target=${{ matrix.target }} --bin=bendsql - - name: Publish macOS - if: matrix.os == 'macos' - shell: bash + - name: Publish Binary + uses: ./.github/actions/publish_binary env: GH_TOKEN: ${{ github.token }} - run: | - mkdir -p dist - tar -czf dist/bendsql-${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release bendsql - gh release upload ${{ github.ref_name }} dist/bendsql-${{ matrix.target }}.tar.gz --clobber - - name: Publish Windows - if: matrix.os == 'windows' - shell: bash - env: - GH_TOKEN: ${{ github.token }} - run: | - mkdir -p dist - 7z a -tzip dist/bendsql-${{ matrix.target }}.zip target/${{ matrix.target }}/release/bendsql.exe - gh release upload ${{ github.ref_name }} dist/bendsql-${{ matrix.target }}.zip --clobber + AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: auto + AWS_ENDPOINT_URL: ${{ secrets.R2_ENDPOINT_URL }} + with: + os: ${{ matrix.os }} + target: ${{ matrix.target }} + version: ${{ github.ref_name }} distribution: needs: build_linux