1
0
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:
Loyalsoldier 2020-10-07 14:29:07 +08:00 committed by GitHub
parent 884feea680
commit 6e4701b700
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 76 deletions

View File

@ -7,41 +7,32 @@ trigger:
- refs/tags/*
pool:
vmImage: 'ubuntu-latest'
vmImage: "ubuntu-latest"
variables:
- group: GithubToken
- name: GOPATH
value: '$(system.defaultWorkingDirectory)/gopath'
- name: BAZEL_VER
value: '3.5.0'
steps:
- checkout: self
- task: GoTool@0
inputs:
version: '1.15.2'
version: "1.15.2"
- script: |
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
workingDirectory: '$(system.defaultWorkingDirectory)'
displayName: 'Fetch sources'
workingDirectory: $(system.defaultWorkingDirectory)
displayName: "Fetch sources"
- script: |
cd ./src/v2ray.com/core || exit 1
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: '$(GOPATH)'
displayName: 'Build Binaries'
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: |
cd ./src/v2ray.com/core || exit 1
echo $RELEASE_TAG
./release/bleedingrelease.sh
workingDirectory: '$(GOPATH)'
displayName: 'Generate Bleeding Edge Release'
workingDirectory: $(system.defaultWorkingDirectory)
displayName: "Generate Bleeding Edge Release"
env:
WORKDIR: $(system.defaultWorkingDirectory)
GITHUB_TOKEN: $(GITHUB_TOKEN)
PRERELEASE: true
RELEASE_TAG: unstable-$(Build.SourceVersion)
@ -50,13 +41,14 @@ steps:
GITHUB_REPO_OWNER: v2fly
GITHUB_REPO_NAME: v2ray-core
- script: |
cd ./src/v2ray.com/core || exit 1
echo $RELEASE_TAG
./release/tagrelease.sh
workingDirectory: '$(GOPATH)'
displayName: 'Generate Tag Release'
workingDirectory: $(system.defaultWorkingDirectory)
displayName: "Generate Tag Release"
env:
WORKDIR: $(system.defaultWorkingDirectory)
GITHUB_TOKEN: $(GITHUB_TOKEN)
PRERELEASE: true
RELEASE_TAG: unstable-$(Build.SourceVersion)
RELEASE_SHA: $(Build.SourceVersion)
TRIGGER_REASON: $(Build.SourceBranch)

View File

@ -6,7 +6,7 @@ def _go_command(ctx):
output_file = ctx.actions.declare_file(ctx.attr.os + "/" + ctx.attr.arch + "/" + ctx.attr.ver + "/" + output)
pkg = ctx.attr.pkg
ld_flags = "-s -w"
ld_flags = "-s -w -buildid="
if ctx.attr.ld:
ld_flags = ld_flags + " " + ctx.attr.ld

View File

@ -1,6 +1,6 @@
#!/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 ${JSON_DATA} | jq -c ".prerelease=${PRERELEASE}")
JSON_DATA=$(echo ${JSON_DATA} | jq -c ".body=\"${RELBODY}\"")
@ -28,7 +28,7 @@ function upload() {
uploadfile $DGST
}
ART_ROOT=$GOPATH/src/v2ray.com/core/bazel-bin/release
ART_ROOT=${WORKDIR}/bazel-bin/release
pushd ${ART_ROOT}
{

View File

@ -4,8 +4,7 @@ CONST_refs="refs"
TRIGGER_REASON_A=${TRIGGER_REASON:0:${#CONST_refs}}
if [ $TRIGGER_REASON_A != $CONST_refs ]
then
if [ $TRIGGER_REASON_A != $CONST_refs ]; then
echo "not a tag: $TRIGGER_REASON_A"
exit
fi
@ -14,18 +13,15 @@ CONST_refsB="refs/tags/"
TRIGGER_REASON_B=${TRIGGER_REASON:0:${#CONST_refsB}}
if [ $TRIGGER_REASON_B != $CONST_refsB ]
then
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 ${GITHUB_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")
@ -52,8 +48,7 @@ function upload() {
uploadfile $DGST
}
ART_ROOT=$GOPATH/src/v2ray.com/core/bazel-bin/release
ART_ROOT=${WORKDIR}/bazel-bin/release
pushd ${ART_ROOT}
{

View File

@ -1,5 +1,4 @@
#!/usr/bin/env bash
# Bash3 Boilerplate. Copyright (c) 2014, kvz.io
set -o errexit
set -o pipefail
@ -8,34 +7,33 @@ set -o nounset
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')
TMP=$(mktemp -d)
SRCDIR=$(pwd)
CODENAME="user"
BUILDNAME=$NOW
VERSIONTAG=$(git describe --tags)
GOPATH=$(go env GOPATH)
cleanup() { rm -rf "$TMP"; }
trap cleanup INT TERM ERR
get_source() {
echo ">>> Getting v2ray sources..."
go get -insecure -v -t v2ray.com/core/...
SRCDIR="$GOPATH/src/v2ray.com/core"
git clone https://github.com/v2fly/v2ray-core.git
pushd v2ray-core
go mod download
}
build_v2() {
pushd "$SRCDIR"
LDFLAGS="-s -w -X v2ray.com/core.codename=${CODENAME} -X v2ray.com/core.build=${BUILDNAME} -X v2ray.com/core.version=${VERSIONTAG}"
if [[ $nosource != 1 ]]; then
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 ..."
env CGO_ENABLED=0 go build -o "$TMP"/v2ray"${EXESUFFIX}" -ldflags "$LDFLAGS" ./main
@ -45,37 +43,36 @@ build_v2() {
echo ">>> Compile v2ctl ..."
env CGO_ENABLED=0 go build -o "$TMP"/v2ctl"${EXESUFFIX}" -tags confonly -ldflags "$LDFLAGS" ./infra/control/main
popd
}
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"
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"
}
copyconf() {
echo ">>> Copying config..."
pushd "$SRCDIR"/release/config
tar c --exclude "*.dat" . | tar x -C "$TMP"
pushd ./release/config
tar c --exclude "*.dat" --exclude "systemd/**" . | tar x -C "$TMP"
}
packzip() {
echo ">>> Generating zip package"
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" .
echo ">>> Generated: $(basename "$PKG")"
echo ">>> Generated: $(basename "$PKG") at $(dirname "$PKG")"
}
packtgz() {
echo ">>> Generating tgz package"
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" .
echo ">>> Generated: $(basename "$PKG")"
echo ">>> Generated: $(basename "$PKG") at $(dirname "$PKG")"
}
packtgzAbPath() {
@ -86,7 +83,6 @@ packtgzAbPath() {
echo ">>> Generated: $ABPATH"
}
pkg=zip
nosource=0
nodat=0
@ -164,6 +160,4 @@ else
packtgzAbPath "$pkg"
fi
cleanup