mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
Build: do NOT rely on GOPATH & refine user-package.sh (#270)
* Build: do NOT rely on GOPATH * Format pipelines
This commit is contained in:
parent
884feea680
commit
6e4701b700
@ -7,41 +7,32 @@ trigger:
|
|||||||
- refs/tags/*
|
- refs/tags/*
|
||||||
|
|
||||||
pool:
|
pool:
|
||||||
vmImage: 'ubuntu-latest'
|
vmImage: "ubuntu-latest"
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
- group: GithubToken
|
- group: GithubToken
|
||||||
- name: GOPATH
|
|
||||||
value: '$(system.defaultWorkingDirectory)/gopath'
|
|
||||||
- name: BAZEL_VER
|
|
||||||
value: '3.5.0'
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- checkout: self
|
- checkout: self
|
||||||
- task: GoTool@0
|
- task: GoTool@0
|
||||||
inputs:
|
inputs:
|
||||||
version: '1.15.2'
|
version: "1.15.2"
|
||||||
- script: |
|
- script: |
|
||||||
go version
|
go version
|
||||||
mkdir -p $GOPATH/src/v2ray.com
|
|
||||||
ln -s $(pwd) $GOPATH/src/v2ray.com/core
|
|
||||||
ls -lah $GOPATH/src/v2ray.com/core
|
|
||||||
cd $GOPATH/src/v2ray.com/core || exit 1
|
|
||||||
go mod download
|
go mod download
|
||||||
workingDirectory: '$(system.defaultWorkingDirectory)'
|
workingDirectory: $(system.defaultWorkingDirectory)
|
||||||
displayName: 'Fetch sources'
|
displayName: "Fetch sources"
|
||||||
- script: |
|
- script: |
|
||||||
cd ./src/v2ray.com/core || exit 1
|
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
|
||||||
bazel build --action_env=GOPATH=$GOPATH --action_env=PATH=$PATH --action_env=SPWD=$PWD --action_env=GOCACHE=$(go env GOCACHE) --spawn_strategy local //release:all
|
workingDirectory: $(system.defaultWorkingDirectory)
|
||||||
workingDirectory: '$(GOPATH)'
|
displayName: "Build Binaries"
|
||||||
displayName: 'Build Binaries'
|
|
||||||
- script: |
|
- script: |
|
||||||
cd ./src/v2ray.com/core || exit 1
|
|
||||||
echo $RELEASE_TAG
|
echo $RELEASE_TAG
|
||||||
./release/bleedingrelease.sh
|
./release/bleedingrelease.sh
|
||||||
workingDirectory: '$(GOPATH)'
|
workingDirectory: $(system.defaultWorkingDirectory)
|
||||||
displayName: 'Generate Bleeding Edge Release'
|
displayName: "Generate Bleeding Edge Release"
|
||||||
env:
|
env:
|
||||||
|
WORKDIR: $(system.defaultWorkingDirectory)
|
||||||
GITHUB_TOKEN: $(GITHUB_TOKEN)
|
GITHUB_TOKEN: $(GITHUB_TOKEN)
|
||||||
PRERELEASE: true
|
PRERELEASE: true
|
||||||
RELEASE_TAG: unstable-$(Build.SourceVersion)
|
RELEASE_TAG: unstable-$(Build.SourceVersion)
|
||||||
@ -50,13 +41,14 @@ steps:
|
|||||||
GITHUB_REPO_OWNER: v2fly
|
GITHUB_REPO_OWNER: v2fly
|
||||||
GITHUB_REPO_NAME: v2ray-core
|
GITHUB_REPO_NAME: v2ray-core
|
||||||
- script: |
|
- script: |
|
||||||
cd ./src/v2ray.com/core || exit 1
|
|
||||||
echo $RELEASE_TAG
|
echo $RELEASE_TAG
|
||||||
./release/tagrelease.sh
|
./release/tagrelease.sh
|
||||||
workingDirectory: '$(GOPATH)'
|
workingDirectory: $(system.defaultWorkingDirectory)
|
||||||
displayName: 'Generate Tag Release'
|
displayName: "Generate Tag Release"
|
||||||
env:
|
env:
|
||||||
|
WORKDIR: $(system.defaultWorkingDirectory)
|
||||||
GITHUB_TOKEN: $(GITHUB_TOKEN)
|
GITHUB_TOKEN: $(GITHUB_TOKEN)
|
||||||
PRERELEASE: true
|
PRERELEASE: true
|
||||||
RELEASE_TAG: unstable-$(Build.SourceVersion)
|
RELEASE_TAG: unstable-$(Build.SourceVersion)
|
||||||
|
RELEASE_SHA: $(Build.SourceVersion)
|
||||||
TRIGGER_REASON: $(Build.SourceBranch)
|
TRIGGER_REASON: $(Build.SourceBranch)
|
||||||
|
@ -6,7 +6,7 @@ def _go_command(ctx):
|
|||||||
output_file = ctx.actions.declare_file(ctx.attr.os + "/" + ctx.attr.arch + "/" + ctx.attr.ver + "/" + output)
|
output_file = ctx.actions.declare_file(ctx.attr.os + "/" + ctx.attr.arch + "/" + ctx.attr.ver + "/" + output)
|
||||||
pkg = ctx.attr.pkg
|
pkg = ctx.attr.pkg
|
||||||
|
|
||||||
ld_flags = "-s -w"
|
ld_flags = "-s -w -buildid="
|
||||||
if ctx.attr.ld:
|
if ctx.attr.ld:
|
||||||
ld_flags = ld_flags + " " + ctx.attr.ld
|
ld_flags = ld_flags + " " + ctx.attr.ld
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
RELBODY="https://www.v2ray.com/chapter_00/01_versions.html"
|
RELBODY="https://github.com/v2fly/v2ray-core/commit/${RELEASE_SHA}"
|
||||||
JSON_DATA=$(echo "{}" | jq -c ".tag_name=\"${RELEASE_TAG}\"")
|
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 ".prerelease=${PRERELEASE}")
|
||||||
JSON_DATA=$(echo ${JSON_DATA} | jq -c ".body=\"${RELBODY}\"")
|
JSON_DATA=$(echo ${JSON_DATA} | jq -c ".body=\"${RELBODY}\"")
|
||||||
@ -28,7 +28,7 @@ function upload() {
|
|||||||
uploadfile $DGST
|
uploadfile $DGST
|
||||||
}
|
}
|
||||||
|
|
||||||
ART_ROOT=$GOPATH/src/v2ray.com/core/bazel-bin/release
|
ART_ROOT=${WORKDIR}/bazel-bin/release
|
||||||
|
|
||||||
pushd ${ART_ROOT}
|
pushd ${ART_ROOT}
|
||||||
{
|
{
|
||||||
|
@ -4,8 +4,7 @@ CONST_refs="refs"
|
|||||||
|
|
||||||
TRIGGER_REASON_A=${TRIGGER_REASON:0:${#CONST_refs}}
|
TRIGGER_REASON_A=${TRIGGER_REASON:0:${#CONST_refs}}
|
||||||
|
|
||||||
if [ $TRIGGER_REASON_A != $CONST_refs ]
|
if [ $TRIGGER_REASON_A != $CONST_refs ]; then
|
||||||
then
|
|
||||||
echo "not a tag: $TRIGGER_REASON_A"
|
echo "not a tag: $TRIGGER_REASON_A"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
@ -14,21 +13,18 @@ CONST_refsB="refs/tags/"
|
|||||||
|
|
||||||
TRIGGER_REASON_B=${TRIGGER_REASON:0:${#CONST_refsB}}
|
TRIGGER_REASON_B=${TRIGGER_REASON:0:${#CONST_refsB}}
|
||||||
|
|
||||||
if [ $TRIGGER_REASON_B != $CONST_refsB ]
|
if [ $TRIGGER_REASON_B != $CONST_refsB ]; then
|
||||||
then
|
|
||||||
echo "not a tag (B)"
|
echo "not a tag (B)"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
GITHUB_RELEASE_TAG=${TRIGGER_REASON:${#CONST_refsB}:25}
|
GITHUB_RELEASE_TAG=${TRIGGER_REASON:${#CONST_refsB}:25}
|
||||||
|
|
||||||
echo ${GITHUB_RELEASE_TAG}
|
echo ${GITHUB_RELEASE_TAG}
|
||||||
|
|
||||||
|
|
||||||
RELEASE_DATA=$(curl -H "Authorization: token ${GITHUB_TOKEN}" -X GET https://api.github.com/repos/v2fly/v2ray-core/releases/tags/${GITHUB_RELEASE_TAG})
|
RELEASE_DATA=$(curl -H "Authorization: token ${GITHUB_TOKEN}" -X GET https://api.github.com/repos/v2fly/v2ray-core/releases/tags/${GITHUB_RELEASE_TAG})
|
||||||
echo $RELEASE_DATA
|
echo $RELEASE_DATA
|
||||||
RELEASE_ID=$(echo $RELEASE_DATA| jq ".id")
|
RELEASE_ID=$(echo $RELEASE_DATA | jq ".id")
|
||||||
|
|
||||||
echo $RELEASE_ID
|
echo $RELEASE_ID
|
||||||
|
|
||||||
@ -44,16 +40,15 @@ function uploadfile() {
|
|||||||
function upload() {
|
function upload() {
|
||||||
FILE=$1
|
FILE=$1
|
||||||
DGST=$1.dgst
|
DGST=$1.dgst
|
||||||
openssl dgst -md5 $FILE | sed 's/([^)]*)//g' >> $DGST
|
openssl dgst -md5 $FILE | sed 's/([^)]*)//g' >>$DGST
|
||||||
openssl dgst -sha1 $FILE | sed 's/([^)]*)//g' >> $DGST
|
openssl dgst -sha1 $FILE | sed 's/([^)]*)//g' >>$DGST
|
||||||
openssl dgst -sha256 $FILE | sed 's/([^)]*)//g' >> $DGST
|
openssl dgst -sha256 $FILE | sed 's/([^)]*)//g' >>$DGST
|
||||||
openssl dgst -sha512 $FILE | sed 's/([^)]*)//g' >> $DGST
|
openssl dgst -sha512 $FILE | sed 's/([^)]*)//g' >>$DGST
|
||||||
uploadfile $FILE
|
uploadfile $FILE
|
||||||
uploadfile $DGST
|
uploadfile $DGST
|
||||||
}
|
}
|
||||||
|
|
||||||
ART_ROOT=$GOPATH/src/v2ray.com/core/bazel-bin/release
|
ART_ROOT=${WORKDIR}/bazel-bin/release
|
||||||
|
|
||||||
|
|
||||||
pushd ${ART_ROOT}
|
pushd ${ART_ROOT}
|
||||||
{
|
{
|
||||||
@ -83,7 +78,7 @@ pushd ${ART_ROOT}
|
|||||||
go run github.com/xiaokangwang/V2BuildAssist/v2buildutil gen file v2ray-openbsd-32.zip
|
go run github.com/xiaokangwang/V2BuildAssist/v2buildutil gen file v2ray-openbsd-32.zip
|
||||||
go run github.com/xiaokangwang/V2BuildAssist/v2buildutil gen file v2ray-dragonfly-64.zip
|
go run github.com/xiaokangwang/V2BuildAssist/v2buildutil gen file v2ray-dragonfly-64.zip
|
||||||
} >Release.unsigned.unsorted
|
} >Release.unsigned.unsorted
|
||||||
go run github.com/xiaokangwang/V2BuildAssist/v2buildutil gen sort < Release.unsigned.unsorted > Release.unsigned
|
go run github.com/xiaokangwang/V2BuildAssist/v2buildutil gen sort <Release.unsigned.unsorted >Release.unsigned
|
||||||
|
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Bash3 Boilerplate. Copyright (c) 2014, kvz.io
|
|
||||||
|
|
||||||
set -o errexit
|
set -o errexit
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
@ -8,74 +7,72 @@ set -o nounset
|
|||||||
|
|
||||||
trap 'echo -e "Aborted, error $? in command: $BASH_COMMAND"; trap ERR; exit 1' ERR
|
trap 'echo -e "Aborted, error $? in command: $BASH_COMMAND"; trap ERR; exit 1' ERR
|
||||||
|
|
||||||
# Set magic variables for current file & dir
|
|
||||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
||||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
|
||||||
__base="$(basename "${__file}" .sh)"
|
|
||||||
__root="$(cd "$(dirname "${__dir}")" && pwd)" # <-- change this as it depends on your app
|
|
||||||
|
|
||||||
|
|
||||||
NOW=$(date '+%Y%m%d-%H%M%S')
|
NOW=$(date '+%Y%m%d-%H%M%S')
|
||||||
TMP=$(mktemp -d)
|
TMP=$(mktemp -d)
|
||||||
SRCDIR=$(pwd)
|
SRCDIR=$(pwd)
|
||||||
|
|
||||||
CODENAME="user"
|
CODENAME="user"
|
||||||
BUILDNAME=$NOW
|
BUILDNAME=$NOW
|
||||||
VERSIONTAG=$(git describe --tags)
|
|
||||||
GOPATH=$(go env GOPATH)
|
|
||||||
|
|
||||||
cleanup () { rm -rf "$TMP"; }
|
cleanup() { rm -rf "$TMP"; }
|
||||||
trap cleanup INT TERM ERR
|
trap cleanup INT TERM ERR
|
||||||
|
|
||||||
get_source() {
|
get_source() {
|
||||||
echo ">>> Getting v2ray sources ..."
|
echo ">>> Getting v2ray sources..."
|
||||||
go get -insecure -v -t v2ray.com/core/...
|
git clone https://github.com/v2fly/v2ray-core.git
|
||||||
SRCDIR="$GOPATH/src/v2ray.com/core"
|
pushd v2ray-core
|
||||||
|
go mod download
|
||||||
}
|
}
|
||||||
|
|
||||||
build_v2() {
|
build_v2() {
|
||||||
pushd "$SRCDIR"
|
if [[ $nosource != 1 ]]; then
|
||||||
LDFLAGS="-s -w -X v2ray.com/core.codename=${CODENAME} -X v2ray.com/core.build=${BUILDNAME} -X v2ray.com/core.version=${VERSIONTAG}"
|
pushd ${SRCDIR}/v2ray-core
|
||||||
|
local VERSIONTAG=$(git describe --abbrev=0 --tags)
|
||||||
|
else
|
||||||
|
echo ">>> Use current directory as WORKDIR"
|
||||||
|
local VERSIONTAG=$(git describe --abbrev=0 --tags)
|
||||||
|
fi
|
||||||
|
|
||||||
|
LDFLAGS="-s -w -buildid= -X v2ray.com/core.codename=${CODENAME} -X v2ray.com/core.build=${BUILDNAME} -X v2ray.com/core.version=${VERSIONTAG}"
|
||||||
|
|
||||||
echo ">>> Compile v2ray ..."
|
echo ">>> Compile v2ray ..."
|
||||||
env CGO_ENABLED=0 go build -o "$TMP"/v2ray"${EXESUFFIX}" -ldflags "$LDFLAGS" ./main
|
env CGO_ENABLED=0 go build -o "$TMP"/v2ray"${EXESUFFIX}" -ldflags "$LDFLAGS" ./main
|
||||||
if [[ $GOOS == "windows" ]];then
|
if [[ $GOOS == "windows" ]]; then
|
||||||
env CGO_ENABLED=0 go build -o "$TMP"/wv2ray"${EXESUFFIX}" -ldflags "-H windowsgui $LDFLAGS" ./main
|
env CGO_ENABLED=0 go build -o "$TMP"/wv2ray"${EXESUFFIX}" -ldflags "-H windowsgui $LDFLAGS" ./main
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ">>> Compile v2ctl ..."
|
echo ">>> Compile v2ctl ..."
|
||||||
env CGO_ENABLED=0 go build -o "$TMP"/v2ctl"${EXESUFFIX}" -tags confonly -ldflags "$LDFLAGS" ./infra/control/main
|
env CGO_ENABLED=0 go build -o "$TMP"/v2ctl"${EXESUFFIX}" -tags confonly -ldflags "$LDFLAGS" ./infra/control/main
|
||||||
popd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
build_dat() {
|
build_dat() {
|
||||||
echo ">>> Downloading newest geoip ..."
|
echo ">>> Download latest geoip..."
|
||||||
curl -s -L -o "$TMP"/geoip.dat "https://github.com/v2fly/geoip/raw/release/geoip.dat"
|
curl -s -L -o "$TMP"/geoip.dat "https://github.com/v2fly/geoip/raw/release/geoip.dat"
|
||||||
|
|
||||||
echo ">>> Downloading newest geosite ..."
|
echo ">>> Download latest geosite..."
|
||||||
curl -s -L -o "$TMP"/geosite.dat "https://github.com/v2fly/domain-list-community/raw/release/dlc.dat"
|
curl -s -L -o "$TMP"/geosite.dat "https://github.com/v2fly/domain-list-community/raw/release/dlc.dat"
|
||||||
}
|
}
|
||||||
|
|
||||||
copyconf() {
|
copyconf() {
|
||||||
echo ">>> Copying config..."
|
echo ">>> Copying config..."
|
||||||
pushd "$SRCDIR"/release/config
|
pushd ./release/config
|
||||||
tar c --exclude "*.dat" . | tar x -C "$TMP"
|
tar c --exclude "*.dat" --exclude "systemd/**" . | tar x -C "$TMP"
|
||||||
}
|
}
|
||||||
|
|
||||||
packzip() {
|
packzip() {
|
||||||
echo ">>> Generating zip package"
|
echo ">>> Generating zip package"
|
||||||
pushd "$TMP"
|
pushd "$TMP"
|
||||||
local PKG=${__dir}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.zip
|
local PKG=${SRCDIR}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.zip
|
||||||
zip -r "$PKG" .
|
zip -r "$PKG" .
|
||||||
echo ">>> Generated: $(basename "$PKG")"
|
echo ">>> Generated: $(basename "$PKG") at $(dirname "$PKG")"
|
||||||
}
|
}
|
||||||
|
|
||||||
packtgz() {
|
packtgz() {
|
||||||
echo ">>> Generating tgz package"
|
echo ">>> Generating tgz package"
|
||||||
pushd "$TMP"
|
pushd "$TMP"
|
||||||
local PKG=${__dir}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.tar.gz
|
local PKG=${SRCDIR}/v2ray-custom-${GOARCH}-${GOOS}-${PKGSUFFIX}${NOW}.tar.gz
|
||||||
tar cvfz "$PKG" .
|
tar cvfz "$PKG" .
|
||||||
echo ">>> Generated: $(basename "$PKG")"
|
echo ">>> Generated: $(basename "$PKG") at $(dirname "$PKG")"
|
||||||
}
|
}
|
||||||
|
|
||||||
packtgzAbPath() {
|
packtgzAbPath() {
|
||||||
@ -86,7 +83,6 @@ packtgzAbPath() {
|
|||||||
echo ">>> Generated: $ABPATH"
|
echo ">>> Generated: $ABPATH"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pkg=zip
|
pkg=zip
|
||||||
nosource=0
|
nosource=0
|
||||||
nodat=0
|
nodat=0
|
||||||
@ -97,7 +93,7 @@ EXESUFFIX=
|
|||||||
PKGSUFFIX=
|
PKGSUFFIX=
|
||||||
|
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
case $arg in
|
case $arg in
|
||||||
arm*)
|
arm*)
|
||||||
GOARCH=$arg
|
GOARCH=$arg
|
||||||
;;
|
;;
|
||||||
@ -136,11 +132,11 @@ case $arg in
|
|||||||
buildname=*)
|
buildname=*)
|
||||||
BUILDNAME=${arg##buildname=}
|
BUILDNAME=${arg##buildname=}
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ $nosource != 1 ]]; then
|
if [[ $nosource != 1 ]]; then
|
||||||
get_source
|
get_source
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export GOOS GOARCH
|
export GOOS GOARCH
|
||||||
@ -149,21 +145,19 @@ echo "PKG ARGS: pkg=${pkg}"
|
|||||||
build_v2
|
build_v2
|
||||||
|
|
||||||
if [[ $nodat != 1 ]]; then
|
if [[ $nodat != 1 ]]; then
|
||||||
build_dat
|
build_dat
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $noconf != 1 ]]; then
|
if [[ $noconf != 1 ]]; then
|
||||||
copyconf
|
copyconf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $pkg == "zip" ]]; then
|
if [[ $pkg == "zip" ]]; then
|
||||||
packzip
|
packzip
|
||||||
elif [[ $pkg == "tgz" ]]; then
|
elif [[ $pkg == "tgz" ]]; then
|
||||||
packtgz
|
packtgz
|
||||||
else
|
else
|
||||||
packtgzAbPath "$pkg"
|
packtgzAbPath "$pkg"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user