From 7381b4dcff177e03b63e7ce4f174eae5c1e6588c Mon Sep 17 00:00:00 2001 From: zhanghongtong Date: Tue, 19 Oct 2021 14:19:21 +0800 Subject: [PATCH] refactor(CI): refactor github action Signed-off-by: zhanghongtong --- .github/workflows/build.yaml | 121 ++++++++++++++++------------------- 1 file changed, 54 insertions(+), 67 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 09f6514..1e4c832 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -6,32 +6,44 @@ on: - "*" - "!v*" jobs: - release: + docker: runs-on: ubuntu-latest - outputs: - upload_url: ${{ steps.create_release.outputs.upload_url }} - tag: ${{ steps.tag.outputs.tag }} + strategy: + fail-fast: false + matrix: + otp: + - "24.0.5-emqx-1" steps: - - name: Get tag - if: startsWith(github.ref, 'refs/tags/') - id: tag - uses: dawidd6/action-get-tag@v1 - - name: Create Release + - uses: actions/checkout@v2 + - uses: docker/setup-qemu-action@v1 + - uses: docker/setup-buildx-action@v1 + - uses: docker/metadata-action@v3 + id: meta + with: + images: ${{ github.repository }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + - uses: docker/login-action@v1 if: startsWith(github.ref, 'refs/tags/') - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: ${{ github.ref }} - release_name: Emqtt Bench ${{ github.ref }} Released - body: Emqtt Bench ${{ github.ref }} Released - draft: false - prerelease: false + username: ${{ secrets.DOCKER_HUB_USER }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + - uses: docker/build-push-action@v2 + with: + context: . + platforms: linux/amd64 + push: ${{ startsWith(github.ref, 'refs/tags/') }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + FROM=ghcr.io/emqx/emqx-builder-helper/5.0:${{ matrix.otp }}-alpine3.14 package: runs-on: ubuntu-latest - needs: release strategy: fail-fast: false matrix: @@ -55,59 +67,34 @@ jobs: - if: failure() run: cat rebar3.crashdump - run: ./_build/emqtt_bench/rel/emqtt_bench/bin/emqtt_bench - - name: Upload Release Asset - if: startsWith(github.ref, 'refs/tags/') - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.release.outputs.upload_url }} - asset_path: ./emqtt-bench-${{ needs.release.outputs.tag }}-${{ matrix.os }}-amd64.tar.gz - asset_name: emqtt-bench-${{ needs.release.outputs.tag }}-${{ matrix.os }}-amd64.tar.gz - asset_content_type: application/tar+gzip - - name: Configure AWS Credentials + - uses: actions/upload-artifact@v2 if: startsWith(github.ref, 'refs/tags/') - uses: aws-actions/configure-aws-credentials@v1 with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ secrets.AWS_DEFAULT_REGION }} - - name: Upload AWS S3 Assert - if: startsWith(github.ref, 'refs/tags/') - run: aws s3 cp ./emqtt-bench-${{ needs.release.outputs.tag }}-${{ matrix.os }}-amd64.tar.gz ${{ secrets.AWS_DEFAULT_REGION }}/emqtt-bench/${{ needs.release.outputs.tag }} + name: packages + path: ./*.tar.gz - docker: + release: runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - otp: - - "24.0.5-emqx-1" + needs: package + if: startsWith(github.ref, 'refs/tags/') + steps: - - uses: actions/checkout@v2 - - uses: docker/setup-qemu-action@v1 - - uses: docker/setup-buildx-action@v1 - - uses: docker/metadata-action@v3 - id: meta + - uses: actions/download-artifact@v2 with: - images: ${{ github.repository }} - tags: | - type=ref,event=branch - type=ref,event=pr - type=ref,event=tag - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - - uses: docker/login-action@v1 - if: startsWith(github.ref, 'refs/tags/') + name: packages + path: packages + - name: Create Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - username: ${{ secrets.DOCKER_HUB_USER }} - password: ${{ secrets.DOCKER_HUB_TOKEN }} - - uses: docker/build-push-action@v2 + tag_name: ${{ github.ref }} + release_name: Emqtt Bench ${{ github.ref }} Released + body: Emqtt Bench ${{ github.ref }} Released + draft: false + prerelease: false + - uses: Rory-Z/upload-release-asset@v1 with: - context: . - platforms: linux/amd64 - push: ${{ startsWith(github.ref, 'refs/tags/') }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - build-args: | - FROM=ghcr.io/emqx/emqx-builder-helper/5.0:${{ matrix.otp }}-alpine3.14 + repo: emqtt-bench + path: "packages/emqtt-bench-*" + token: ${{ github.token }}