Browse Source

Build: do NOT rely on GOPATH & refine user-package.sh (#270)

* Build: do NOT rely on GOPATH

* Format pipelines
pull/2757/head
Loyalsoldier 4 years ago committed by GitHub
parent
commit
6e4701b700
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      azure-pipelines.yml
  2. 2
      infra/bazel/build.bzl
  3. 4
      release/bleedingrelease.sh
  4. 23
      release/tagrelease.sh
  5. 68
      release/user-package.sh

36
azure-pipelines.yml

@ -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)

2
infra/bazel/build.bzl

@ -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

4
release/bleedingrelease.sh

@ -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}
{

23
release/tagrelease.sh

@ -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,21 +13,18 @@ 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")
RELEASE_ID=$(echo $RELEASE_DATA | jq ".id")
echo $RELEASE_ID
@ -44,16 +40,15 @@ function uploadfile() {
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
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=$GOPATH/src/v2ray.com/core/bazel-bin/release
ART_ROOT=${WORKDIR}/bazel-bin/release
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-dragonfly-64.zip
} >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

68
release/user-package.sh

@ -1,5 +1,4 @@
#!/usr/bin/env bash
# Bash3 Boilerplate. Copyright (c) 2014, kvz.io
set -o errexit
set -o pipefail
@ -8,74 +7,72 @@ 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"; }
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"
echo ">>> Getting v2ray sources..."
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
if [[ $GOOS == "windows" ]];then
env CGO_ENABLED=0 go build -o "$TMP"/wv2ray"${EXESUFFIX}" -ldflags "-H windowsgui $LDFLAGS" ./main
if [[ $GOOS == "windows" ]]; then
env CGO_ENABLED=0 go build -o "$TMP"/wv2ray"${EXESUFFIX}" -ldflags "-H windowsgui $LDFLAGS" ./main
fi
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
@ -97,7 +93,7 @@ EXESUFFIX=
PKGSUFFIX=
for arg in "$@"; do
case $arg in
case $arg in
arm*)
GOARCH=$arg
;;
@ -136,11 +132,11 @@ case $arg in
buildname=*)
BUILDNAME=${arg##buildname=}
;;
esac
esac
done
if [[ $nosource != 1 ]]; then
get_source
get_source
fi
export GOOS GOARCH
@ -149,21 +145,19 @@ echo "PKG ARGS: pkg=${pkg}"
build_v2
if [[ $nodat != 1 ]]; then
build_dat
build_dat
fi
if [[ $noconf != 1 ]]; then
copyconf
copyconf
fi
if [[ $pkg == "zip" ]]; then
packzip
packzip
elif [[ $pkg == "tgz" ]]; then
packtgz
packtgz
else
packtgzAbPath "$pkg"
fi
cleanup

Loading…
Cancel
Save