From eeee50962c4dd550b9fa5a9e340a6621e00ed298 Mon Sep 17 00:00:00 2001 From: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Tue, 24 Nov 2020 13:19:23 +0800 Subject: [PATCH] Migrate release from Azure Pipelines to GitHub Actions --- .github/workflows/release.yml | 81 +++++++++++++++++++++++++ azure-pipelines.yml | 54 ----------------- release/bleedingrelease.sh | 94 ----------------------------- release/release.sh | 68 +++++++++++++++++++++ release/tagrelease.sh | 108 ---------------------------------- 5 files changed, 149 insertions(+), 256 deletions(-) create mode 100644 .github/workflows/release.yml delete mode 100644 azure-pipelines.yml delete mode 100755 release/bleedingrelease.sh create mode 100644 release/release.sh delete mode 100755 release/tagrelease.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..0997130a88 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,81 @@ +name: Release + +on: + release: + types: [prereleased] + push: + branches: + - master + - v* + - dev* + paths: + - "**/*.go" + - "go.mod" + - "go.sum" + - ".github/workflows/*.yml" + - ".github/workflows/*.yaml" + pull_request: + types: [opened, synchronize, reopened] + paths: + - "**/*.go" + - "go.mod" + - "go.sum" + - ".github/workflows/*.yml" + - ".github/workflows/*.yaml" + +jobs: + release: + if: github.repository != 'v2ray/v2ray-core' + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: 1.15 + + - name: Checkout codebase + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Get project dependencies + run: go mod download + + - name: Set variables + run: | + echo "BleedingReleaseTag=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV + echo "TagReleaseTag=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_ENV + shell: bash + + - name: Build binaries + run: bazel build --action_env=PATH=$PATH --action_env=GOPATH=$(go env GOPATH) --action_env=GOCACHE=$(go env GOCACHE) --action_env=SPWD=$(pwd) --spawn_strategy local //release:all + + - name: Upload binaries to repo "v2fly/V2FlyBleedingEdgeBinary" + if: github.event_name != 'release' && github.repository == 'v2fly/v2ray-core' + env: + IsBleedingRelease: true + WORKDIR: ${{ github.workspace }} + PRERELEASE: true + RELEASE_SHA: ${{ github.sha }} + RELEASE_TAG: ${{ env.BleedingReleaseTag }} + UPLOAD_REPO: v2fly/V2FlyBleedingEdgeBinary + PERSONAL_TOKEN: ${{ secrets.BLEEDINGEDGEBINARY_REPO_TOKEN }} + COMMENT_TARGETTED_REPO_OWNER: v2fly + COMMENT_TARGETTED_REPO_NAME: v2ray-core + run: | + chmod u+x ./release/release.sh + ./release/release.sh + + - name: Upload binaries to current repo + if: github.event_name == 'release' + env: + IsBleedingRelease: false + WORKDIR: ${{ github.workspace }} + PRERELEASE: true + RELEASE_SHA: ${{ github.sha }} + RELEASE_TAG: ${{ env.TagReleaseTag }} + UPLOAD_REPO: ${{ github.repository }} + PERSONAL_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + chmod u+x ./release/release.sh + ./release/release.sh diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 92bb6593ba..0000000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,54 +0,0 @@ -trigger: - batch: true - branches: - include: - - master - - dev* - - refs/tags/* - -pool: - vmImage: "ubuntu-latest" - -variables: - - group: GithubToken - -steps: - - checkout: self - - task: GoTool@0 - inputs: - version: "1.15.5" - - script: | - go version - go mod download - workingDirectory: $(system.defaultWorkingDirectory) - displayName: "Fetch sources" - - script: | - bazel build --action_env=PATH=$PATH --action_env=GOPATH=$(go env GOPATH) --action_env=GOCACHE=$(go env GOCACHE) --action_env=SPWD=$(pwd) --spawn_strategy local //release:all - workingDirectory: $(system.defaultWorkingDirectory) - displayName: "Build Binaries" - - script: | - echo $RELEASE_TAG - ./release/bleedingrelease.sh - workingDirectory: $(system.defaultWorkingDirectory) - displayName: "Generate Bleeding Edge Release" - env: - WORKDIR: $(system.defaultWorkingDirectory) - PERSONAL_TOKEN: $(GITHUB_TOKEN) - PRERELEASE: true - RELEASE_TAG: unstable-$(Build.SourceVersion) - RELEASE_SHA: $(Build.SourceVersion) - TRIGGER_REASON: $(Build.SourceBranch) - COMMENT_TARGETTED_REPO_OWNER: v2fly - COMMENT_TARGETTED_REPO_NAME: v2ray-core - - script: | - echo $RELEASE_TAG - ./release/tagrelease.sh - workingDirectory: $(system.defaultWorkingDirectory) - displayName: "Generate Tag Release" - env: - WORKDIR: $(system.defaultWorkingDirectory) - PERSONAL_TOKEN: $(GITHUB_TOKEN) - PRERELEASE: true - RELEASE_TAG: unstable-$(Build.SourceVersion) - RELEASE_SHA: $(Build.SourceVersion) - TRIGGER_REASON: $(Build.SourceBranch) diff --git a/release/bleedingrelease.sh b/release/bleedingrelease.sh deleted file mode 100755 index 913105d9d9..0000000000 --- a/release/bleedingrelease.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env bash - -RELBODY="https://github.com/v2fly/v2ray-core/commit/${RELEASE_SHA}" -JSON_DATA=$(echo "{}" | jq -c ".tag_name=\"${RELEASE_TAG}\"") -JSON_DATA=$(echo ${JSON_DATA} | jq -c ".prerelease=${PRERELEASE}") -JSON_DATA=$(echo ${JSON_DATA} | jq -c ".body=\"${RELBODY}\"") -RELEASE_DATA=$(curl --data "${JSON_DATA}" -H "Authorization: token ${PERSONAL_TOKEN}" -X POST https://api.github.com/repos/v2fly/V2FlyBleedingEdgeBinary/releases) -echo $RELEASE_DATA -RELEASE_ID=$(echo $RELEASE_DATA | jq ".id") - -function uploadfile() { - FILE=$1 - CTYPE=$(file -b --mime-type $FILE) - - sleep 1 - curl -H "Authorization: token ${PERSONAL_TOKEN}" -H "Content-Type: ${CTYPE}" --data-binary @$FILE "https://uploads.github.com/repos/v2fly/V2FlyBleedingEdgeBinary/releases/${RELEASE_ID}/assets?name=$(basename $FILE)" - sleep 1 -} - -function upload() { - FILE=$1 - DGST=$1.dgst - openssl dgst -md5 $FILE | sed 's/([^)]*)//g' >>$DGST - openssl dgst -sha1 $FILE | sed 's/([^)]*)//g' >>$DGST - openssl dgst -sha256 $FILE | sed 's/([^)]*)//g' >>$DGST - openssl dgst -sha512 $FILE | sed 's/([^)]*)//g' >>$DGST - uploadfile $FILE - uploadfile $DGST -} - -ART_ROOT=${WORKDIR}/bazel-bin/release - -pushd ${ART_ROOT} -{ - go run github.com/v2fly/V2BuildAssist/v2buildutil gen version ${RELEASE_TAG} - go run github.com/v2fly/V2BuildAssist/v2buildutil gen project "v2flyunstable" - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-macos-64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-windows-64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-windows-32.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-windows-arm32-v7a.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-32.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-arm64-v8a.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-arm32-v7a.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-arm32-v6.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-arm32-v5.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-mips64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-mips64le.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-mips32.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-mips32le.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-ppc64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-ppc64le.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-riscv64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-s390x.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-freebsd-64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-freebsd-32.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-openbsd-64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-openbsd-32.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-dragonfly-64.zip -} >Release.unsigned.unsorted - go run github.com/v2fly/V2BuildAssist/v2buildutil gen sort < Release.unsigned.unsorted > Release.unsigned - - { - echo "Build Finished" - echo "https://github.com/v2fly/V2FlyBleedingEdgeBinary/releases/tag/${RELEASE_TAG}" - } > buildcomment - - go run github.com/v2fly/V2BuildAssist/v2buildutil post commit "${RELEASE_SHA}" < buildcomment -popd - -upload ${ART_ROOT}/v2ray-macos-64.zip -upload ${ART_ROOT}/v2ray-windows-64.zip -upload ${ART_ROOT}/v2ray-windows-32.zip -upload ${ART_ROOT}/v2ray-windows-arm32-v7a.zip -upload ${ART_ROOT}/v2ray-linux-64.zip -upload ${ART_ROOT}/v2ray-linux-32.zip -upload ${ART_ROOT}/v2ray-linux-arm64-v8a.zip -upload ${ART_ROOT}/v2ray-linux-arm32-v7a.zip -upload ${ART_ROOT}/v2ray-linux-arm32-v6.zip -upload ${ART_ROOT}/v2ray-linux-arm32-v5.zip -upload ${ART_ROOT}/v2ray-linux-mips64.zip -upload ${ART_ROOT}/v2ray-linux-mips64le.zip -upload ${ART_ROOT}/v2ray-linux-mips32.zip -upload ${ART_ROOT}/v2ray-linux-mips32le.zip -upload ${ART_ROOT}/v2ray-linux-ppc64.zip -upload ${ART_ROOT}/v2ray-linux-ppc64le.zip -upload ${ART_ROOT}/v2ray-linux-riscv64.zip -upload ${ART_ROOT}/v2ray-linux-s390x.zip -upload ${ART_ROOT}/v2ray-freebsd-64.zip -upload ${ART_ROOT}/v2ray-freebsd-32.zip -upload ${ART_ROOT}/v2ray-openbsd-64.zip -upload ${ART_ROOT}/v2ray-openbsd-32.zip -upload ${ART_ROOT}/v2ray-dragonfly-64.zip -upload ${ART_ROOT}/Release.unsigned diff --git a/release/release.sh b/release/release.sh new file mode 100644 index 0000000000..2637d95ed3 --- /dev/null +++ b/release/release.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +ART_ROOT=${WORKDIR}/bazel-bin/release + +pushd ${ART_ROOT} || exit 1 + +# Generate Release.unsigned.unsorted file +{ + go run github.com/v2fly/V2BuildAssist/v2buildutil gen version ${RELEASE_TAG} + go run github.com/v2fly/V2BuildAssist/v2buildutil gen project "v2fly" + for zip in $(find -L . -type f -name "*.zip"); do + go run github.com/v2fly/V2BuildAssist/v2buildutil gen file ${zip} + done +} >Release.unsigned.unsorted + +# Generate Release.unsigned file +go run github.com/v2fly/V2BuildAssist/v2buildutil gen sort < Release.unsigned.unsorted > Release.unsigned +rm -f Release.unsigned.unsorted + +# Test if is bleeding edge release +if [[ "$IsBleedingRelease" == true ]]; then + # If it is a bleeding edge release + # Prepare JSON data, create a release and get release id + RELBODY="https://github.com/${COMMENT_TARGETTED_REPO_OWNER}/${COMMENT_TARGETTED_REPO_NAME}/commit/${RELEASE_SHA}" + JSON_DATA=$(echo "{}" | jq -c ".tag_name=\"${RELEASE_TAG}\"") + JSON_DATA=$(echo ${JSON_DATA} | jq -c ".name=\"${RELEASE_TAG}\"") + JSON_DATA=$(echo ${JSON_DATA} | jq -c ".prerelease=${PRERELEASE}") + JSON_DATA=$(echo ${JSON_DATA} | jq -c ".body=\"${RELBODY}\"") + RELEASE_DATA=$(curl -X POST --data "${JSON_DATA}" -H "Authorization: token ${PERSONAL_TOKEN}" "https://api.github.com/repos/${UPLOAD_REPO}/releases") + echo "Bleeding Edge Release data:" + echo $RELEASE_DATA + RELEASE_ID=$(echo $RELEASE_DATA | jq ".id") + + # Prepare commit comment message and post it + echo "Build Finished" > buildcomment + echo "https://github.com/${UPLOAD_REPO}/releases/tag/${RELEASE_TAG}" >> buildcomment + go run github.com/v2fly/V2BuildAssist/v2buildutil post commit "${RELEASE_SHA}" < buildcomment + rm -f buildcomment +else + # If is a tag release then get the release id + RELEASE_DATA=$(curl -X GET -H "Authorization: token ${PERSONAL_TOKEN}" "https://api.github.com/repos/${UPLOAD_REPO}/releases/tags/${RELEASE_TAG}") + echo "Tag Release data:" + echo $RELEASE_DATA + RELEASE_ID=$(echo $RELEASE_DATA | jq ".id") +fi + +function uploadfile() { + FILE=$1 + CTYPE=$(file -b --mime-type $FILE) + + curl -H "Authorization: token ${PERSONAL_TOKEN}" -H "Content-Type: ${CTYPE}" --data-binary @$FILE "https://uploads.github.com/repos/${UPLOAD_REPO}/releases/${RELEASE_ID}/assets?name=$(basename $FILE)" +} + +function upload() { + FILE=$1 + DGST=$1.dgst + openssl dgst -md5 $FILE | sed 's/([^)]*)//g' >>$DGST + openssl dgst -sha1 $FILE | sed 's/([^)]*)//g' >>$DGST + openssl dgst -sha256 $FILE | sed 's/([^)]*)//g' >>$DGST + openssl dgst -sha512 $FILE | sed 's/([^)]*)//g' >>$DGST + uploadfile $FILE + uploadfile $DGST +} + +# Upload all files to release assets +for asset in $(find -L . -type f -name "*.zip" -or -type f -name "*.unsigned"); do + upload ${asset} +done diff --git a/release/tagrelease.sh b/release/tagrelease.sh deleted file mode 100755 index c08f339abc..0000000000 --- a/release/tagrelease.sh +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env bash - -CONST_refs="refs" - -TRIGGER_REASON_A=${TRIGGER_REASON:0:${#CONST_refs}} - -if [ $TRIGGER_REASON_A != $CONST_refs ]; then - echo "not a tag: $TRIGGER_REASON_A" - exit -fi - -CONST_refsB="refs/tags/" - -TRIGGER_REASON_B=${TRIGGER_REASON:0:${#CONST_refsB}} - -if [ $TRIGGER_REASON_B != $CONST_refsB ]; then - echo "not a tag (B)" - exit -fi - -GITHUB_RELEASE_TAG=${TRIGGER_REASON:${#CONST_refsB}:25} - -echo ${GITHUB_RELEASE_TAG} - -RELEASE_DATA=$(curl -H "Authorization: token ${PERSONAL_TOKEN}" -X GET https://api.github.com/repos/v2fly/v2ray-core/releases/tags/${GITHUB_RELEASE_TAG}) -echo $RELEASE_DATA -RELEASE_ID=$(echo $RELEASE_DATA | jq ".id") - -echo $RELEASE_ID - -function uploadfile() { - FILE=$1 - CTYPE=$(file -b --mime-type $FILE) - - sleep 1 - curl -H "Authorization: token ${PERSONAL_TOKEN}" -H "Content-Type: ${CTYPE}" --data-binary @$FILE "https://uploads.github.com/repos/v2fly/v2ray-core/releases/${RELEASE_ID}/assets?name=$(basename $FILE)" - sleep 1 -} - -function upload() { - FILE=$1 - DGST=$1.dgst - openssl dgst -md5 $FILE | sed 's/([^)]*)//g' >>$DGST - openssl dgst -sha1 $FILE | sed 's/([^)]*)//g' >>$DGST - openssl dgst -sha256 $FILE | sed 's/([^)]*)//g' >>$DGST - openssl dgst -sha512 $FILE | sed 's/([^)]*)//g' >>$DGST - uploadfile $FILE - uploadfile $DGST -} - -ART_ROOT=${WORKDIR}/bazel-bin/release - -pushd ${ART_ROOT} -{ - go run github.com/v2fly/V2BuildAssist/v2buildutil gen version "${GITHUB_RELEASE_TAG}" - go run github.com/v2fly/V2BuildAssist/v2buildutil gen project "v2fly" - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-macos-64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-windows-64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-windows-32.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-windows-arm32-v7a.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-32.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-arm64-v8a.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-arm32-v7a.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-arm32-v6.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-arm32-v5.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-mips64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-mips64le.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-mips32.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-mips32le.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-ppc64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-ppc64le.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-riscv64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-linux-s390x.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-freebsd-64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-freebsd-32.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-openbsd-64.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-openbsd-32.zip - go run github.com/v2fly/V2BuildAssist/v2buildutil gen file v2ray-dragonfly-64.zip -} >Release.unsigned.unsorted -go run github.com/v2fly/V2BuildAssist/v2buildutil gen sort Release.unsigned - -popd - -upload ${ART_ROOT}/v2ray-macos-64.zip -upload ${ART_ROOT}/v2ray-windows-64.zip -upload ${ART_ROOT}/v2ray-windows-32.zip -upload ${ART_ROOT}/v2ray-windows-arm32-v7a.zip -upload ${ART_ROOT}/v2ray-linux-64.zip -upload ${ART_ROOT}/v2ray-linux-32.zip -upload ${ART_ROOT}/v2ray-linux-arm64-v8a.zip -upload ${ART_ROOT}/v2ray-linux-arm32-v7a.zip -upload ${ART_ROOT}/v2ray-linux-arm32-v6.zip -upload ${ART_ROOT}/v2ray-linux-arm32-v5.zip -upload ${ART_ROOT}/v2ray-linux-mips64.zip -upload ${ART_ROOT}/v2ray-linux-mips64le.zip -upload ${ART_ROOT}/v2ray-linux-mips32.zip -upload ${ART_ROOT}/v2ray-linux-mips32le.zip -upload ${ART_ROOT}/v2ray-linux-ppc64.zip -upload ${ART_ROOT}/v2ray-linux-ppc64le.zip -upload ${ART_ROOT}/v2ray-linux-riscv64.zip -upload ${ART_ROOT}/v2ray-linux-s390x.zip -upload ${ART_ROOT}/v2ray-freebsd-64.zip -upload ${ART_ROOT}/v2ray-freebsd-32.zip -upload ${ART_ROOT}/v2ray-openbsd-64.zip -upload ${ART_ROOT}/v2ray-openbsd-32.zip -upload ${ART_ROOT}/v2ray-dragonfly-64.zip -upload ${ART_ROOT}/Release.unsigned