Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate release from Azure Pipelines to GitHub Actions
- Loading branch information
1 parent
b93f69f
commit eeee509
Showing
5 changed files
with
149 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.