Просмотр исходного кода

build(CI): update build packages workflows

zhanghongtong 5 лет назад
Родитель
Сommit
7a915efaa2

+ 0 - 62
.ci/build_packages/upload_github_release_asset.sh

@@ -1,62 +0,0 @@
-#!/usr/bin/env bash
-#
-# Author: Stefan Buck
-# License: MIT
-# https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447
-#
-#
-# This script accepts the following parameters:
-#
-# * owner
-# * repo
-# * tag
-# * filename
-# * github_api_token
-#
-# Script to upload a release asset using the GitHub API v3.
-#
-# Example:
-#
-# upload-github-release-asset.sh github_api_token=TOKEN owner=stefanbuck repo=playground tag=v0.1.0 filename=./build.zip
-#
-
-# Check dependencies.
-set -e
-xargs=$(which gxargs || which xargs)
-
-# Validate settings.
-[ "$TRACE" ] && set -x
-
-CONFIG=$@
-
-for line in $CONFIG; do
-  eval "$line"
-done
-
-# Define variables.
-GH_API="https://api.github.com"
-GH_REPO="$GH_API/repos/$owner/$repo"
-GH_TAGS="$GH_REPO/releases/tags/$tag"
-AUTH="Authorization: token $github_api_token"
-WGET_ARGS="--content-disposition --auth-no-challenge --no-cookie"
-CURL_ARGS="-LJO#"
-
-if [[ "$tag" == 'LATEST' ]]; then
-  GH_TAGS="$GH_REPO/releases/latest"
-fi
-
-# Validate token.
-curl -o /dev/null -sH "$AUTH" $GH_REPO || { echo "Error: Invalid repo, token or network issue!";  exit 1; }
-
-# Read asset tags.
-response=$(curl -sH "$AUTH" $GH_TAGS)
-
-# Get ID of the asset based on given filename.
-eval $(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
-[ "$id" ] || { echo "Error: Failed to get release id for tag: $tag"; echo "$response" | awk 'length($0)<100' >&2; exit 1; }
-
-# Upload asset
-# Construct url
-GH_ASSET="https://uploads.github.com/repos/$owner/$repo/releases/$id/assets?name=$(basename $filename)"
-
-curl "$GITHUB_OAUTH_BASIC" --data-binary @"$filename" -H "Authorization: token $github_api_token" -H "Content-Type: application/octet-stream" $GH_ASSET

+ 16 - 19
.github/workflows/build_packages.yaml

@@ -281,6 +281,10 @@ jobs:
     if: startsWith(github.ref, 'refs/tags/')
 
     steps:
+    - user: get_version
+      run: |
+        version=$(echo ${{ github.ref }} | sed -r  "s ^refs/heads/|^refs/tags/(.*) \1 g")
+        echo "VERSION=$verison" >> $GITHUB_ENV
     - uses: actions/download-artifact@v2
       with:
         name: emqx
@@ -305,17 +309,13 @@ jobs:
     - name: upload aws s3
       run: |
         set -e -x -u
-        version=$(echo ${{ github.ref }} | sed -r  "s ^refs/heads/|^refs/tags/(.*) \1 g")
-        curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
-        unzip -q awscliv2.zip
-        sudo ./aws/install
         aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
         aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
         aws configure set default.region us-west-2
 
-        aws s3 cp --recursive _packages/emqx s3://packages.emqx/emqx-ce/$version
-        aws s3 cp --recursive _packages/emqx-edge s3://packages.emqx/emqx-edge/$version
-        aws cloudfront create-invalidation --distribution-id E170YEULGLT8XB --paths "/emqx-ce/$version/*,/emqx-edge/$version/*"
+        aws s3 cp --recursive _packages/emqx s3://packages.emqx/emqx-ce/$VERSION
+        aws s3 cp --recursive _packages/emqx-edge s3://packages.emqx/emqx-edge/$VERSION
+        aws cloudfront create-invalidation --distribution-id E170YEULGLT8XB --paths "/emqx-ce/$VERSION/*,/emqx-edge/$VERSION/*"
 
         mkdir packages
         mv _packages/emqx/* packages
@@ -323,28 +323,27 @@ jobs:
     - uses: actions/checkout@v2
       with:
         path: emqx
-    - name: update to github and emqx.io
+    - uses: Rory-Z/upload-release-asset@v1
+      if: github.event_name == 'release'
+      with:
+        repo: emqx
+        path: "packages/emqx-*"
+        token: ${{ secrets.AccessToken }}
+    - name: update to emqx.io
       if: github.event_name == 'release'
       run: |
         set -e -x -u
-        version=$(echo ${{ github.ref }} | sed -r  "s ^refs/heads/|^refs/tags/(.*) \1 g")
-        cd packages
-        for var in $(ls); do
-          ../emqx/.ci/build_packages/upload_github_release_asset.sh owner=emqx repo=emqx tag=$version filename=$var github_api_token=$(echo ${{ secrets.AccessToken }})
-          sleep 1
-        done
         curl -w %{http_code} \
              --insecure \
              -H "Content-Type: application/json" \
              -H "token: ${{ secrets.EMQX_IO_TOKEN }}" \
              -X POST \
-             -d "{\"repo\":\"emqx/emqx\", \"tag\": \"${version}\" }" \
+             -d "{\"repo\":\"emqx/emqx\", \"tag\": \"${VERSION}\" }" \
              ${{ secrets.EMQX_IO_RELEASE_API }}
     - name: push docker image to docker hub
       if: github.event_name == 'release'
       run: |
         set -e -x -u
-        version=$(echo ${{ github.ref }} | sed -r  "s ^refs/heads/|^refs/tags/(.*) \1 g")
         sudo make -C emqx docker-prepare
         cd packages && for var in $(ls |grep docker |grep -v sha256); do unzip $var; sudo docker load < ${var%.*}; rm -f ${var%.*}; done && cd -
         echo ${{ secrets.DOCKER_HUB_TOKEN }} |sudo docker login -u ${{ secrets.DOCKER_HUB_USER }} --password-stdin
@@ -356,12 +355,11 @@ jobs:
       if: github.event_name == 'release'
       run: |
         set -e -x -u
-        version=$(echo ${{ github.ref }} | sed -r  "s ^refs/heads/|^refs/tags/(.*) \1 g")
         curl \
           -H "Authorization: token ${{ secrets.AccessToken }}" \
           -H "Accept: application/vnd.github.v3+json" \
           -X POST \
-          -d "{\"ref\":\"v1.0.0\",\"inputs\":{\"version\": \"${version}\", \"emqx_ce\": \"true\"}}" \
+          -d "{\"ref\":\"v1.0.0\",\"inputs\":{\"version\": \"${VERSION}\", \"emqx_ce\": \"true\"}}" \
           https://api.github.com/repos/emqx/emqx-ci-helper/actions/workflows/update_repos.yaml/dispatches
     - uses: geekyeggo/delete-artifact@v1
       with:
@@ -371,7 +369,6 @@ jobs:
         name: emqx-edge
     # - name: update homebrew packages
     #   run: |
-    #     version=$(echo ${{ github.ref }} | sed -r  "s .*/.*/(.*) \1 g")
     #     if [ ! -z $(echo $version | grep -oE "v[0-9]+\.[0-9]+(\.[0-9]+)?") ] && [ -z $(echo $version | grep -oE "(alpha|beta|rc)\.[0-9]") ]; then
     #       curl -H "Authorization: token ${{ secrets.AccessToken }}" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" -X POST -d "{\"event_type\":\"update_homebrew\",\"client_payload\":{\"version\": \"$version\"}}" https://api.github.com/repos/emqx/emqx-packages-docker/dispatches
     #     fi