2021-03-02 16:46:50 +02:00
|
|
|
name: Build and Release
|
|
|
|
|
2024-04-29 02:13:59 +03:00
|
|
|
# NOTE: This Github Actions file depends on the Makefile.
|
|
|
|
# Building the correct package requires the correct binaries generated by the Makefile. To
|
|
|
|
# ensure the correct output, the Makefile must accept the appropriate input and compile the
|
|
|
|
# correct file with the correct name. If you need to modify this file, please ensure it won't
|
|
|
|
# disrupt the Makefile.
|
|
|
|
|
2021-03-02 16:46:50 +02:00
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
release:
|
|
|
|
types: [published]
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
paths:
|
|
|
|
- "**/*.go"
|
|
|
|
- "go.mod"
|
|
|
|
- "go.sum"
|
2024-06-05 21:31:48 +03:00
|
|
|
- ".github/workflows/release.yml"
|
2021-03-02 16:46:50 +02:00
|
|
|
pull_request:
|
|
|
|
types: [opened, synchronize, reopened]
|
|
|
|
paths:
|
|
|
|
- "**/*.go"
|
|
|
|
- "go.mod"
|
|
|
|
- "go.sum"
|
2024-06-05 21:31:48 +03:00
|
|
|
- ".github/workflows/release.yml"
|
2021-03-02 16:46:50 +02:00
|
|
|
jobs:
|
2023-02-25 04:26:28 +02:00
|
|
|
prepare:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: Restore Cache
|
2024-01-18 02:15:36 +02:00
|
|
|
uses: actions/cache/restore@v4
|
2023-02-25 04:26:28 +02:00
|
|
|
with:
|
|
|
|
path: resources
|
|
|
|
key: xray-geodat-
|
|
|
|
|
|
|
|
- name: Update Geodat
|
|
|
|
id: update
|
2024-02-01 02:31:18 +02:00
|
|
|
uses: nick-fields/retry@v3
|
2023-02-25 04:26:28 +02:00
|
|
|
with:
|
|
|
|
timeout_minutes: 60
|
|
|
|
retry_wait_seconds: 60
|
|
|
|
max_attempts: 60
|
|
|
|
command: |
|
|
|
|
[ -d 'resources' ] || mkdir resources
|
|
|
|
LIST=('geoip geoip geoip' 'domain-list-community dlc geosite')
|
|
|
|
for i in "${LIST[@]}"
|
|
|
|
do
|
|
|
|
INFO=($(echo $i | awk 'BEGIN{FS=" ";OFS=" "} {print $1,$2,$3}'))
|
|
|
|
FILE_NAME="${INFO[2]}.dat"
|
|
|
|
echo -e "Verifying HASH key..."
|
|
|
|
HASH="$(curl -sL "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat.sha256sum" | awk -F ' ' '{print $1}')"
|
|
|
|
if [ -s "./resources/${FILE_NAME}" ] && [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ]; then
|
|
|
|
continue
|
|
|
|
else
|
|
|
|
echo -e "Downloading https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat..."
|
|
|
|
curl -L "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat" -o ./resources/${FILE_NAME}
|
|
|
|
echo -e "Verifying HASH key..."
|
|
|
|
[ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ] || { echo -e "The HASH key of ${FILE_NAME} does not match cloud one."; exit 1; }
|
|
|
|
echo "unhit=true" >> $GITHUB_OUTPUT
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
- name: Save Cache
|
2024-01-18 02:15:36 +02:00
|
|
|
uses: actions/cache/save@v4
|
2023-02-25 04:26:28 +02:00
|
|
|
if: ${{ steps.update.outputs.unhit }}
|
|
|
|
with:
|
|
|
|
path: resources
|
|
|
|
key: xray-geodat-${{ github.sha }}-${{ github.run_number }}
|
|
|
|
|
2021-03-02 16:46:50 +02:00
|
|
|
build:
|
2023-02-25 04:26:28 +02:00
|
|
|
needs: prepare
|
2022-02-20 05:53:11 +02:00
|
|
|
permissions:
|
|
|
|
contents: write
|
2021-03-02 16:46:50 +02:00
|
|
|
strategy:
|
|
|
|
matrix:
|
|
|
|
# Include amd64 on all platforms.
|
2023-11-12 21:28:36 +02:00
|
|
|
goos: [windows, freebsd, openbsd, linux, darwin]
|
2021-03-02 16:46:50 +02:00
|
|
|
goarch: [amd64, 386]
|
2024-07-15 12:53:40 +03:00
|
|
|
gotoolchain: [""]
|
|
|
|
patch-assetname: [""]
|
2021-03-02 16:46:50 +02:00
|
|
|
exclude:
|
2023-11-12 21:28:36 +02:00
|
|
|
# Exclude i386 on darwin
|
2021-03-02 16:46:50 +02:00
|
|
|
- goarch: 386
|
|
|
|
goos: darwin
|
|
|
|
include:
|
2024-07-12 01:20:06 +03:00
|
|
|
# BEGIN MacOS ARM64
|
2021-03-02 16:46:50 +02:00
|
|
|
- goos: darwin
|
|
|
|
goarch: arm64
|
|
|
|
# END MacOS ARM64
|
|
|
|
# BEGIN Linux ARM 5 6 7
|
|
|
|
- goos: linux
|
|
|
|
goarch: arm
|
|
|
|
goarm: 7
|
|
|
|
- goos: linux
|
|
|
|
goarch: arm
|
|
|
|
goarm: 6
|
|
|
|
- goos: linux
|
|
|
|
goarch: arm
|
|
|
|
goarm: 5
|
|
|
|
# END Linux ARM 5 6 7
|
|
|
|
# BEGIN Android ARM 8
|
|
|
|
- goos: android
|
|
|
|
goarch: arm64
|
|
|
|
# END Android ARM 8
|
2021-09-25 20:35:58 +03:00
|
|
|
# Windows ARM
|
|
|
|
- goos: windows
|
|
|
|
goarch: arm64
|
2021-03-02 16:46:50 +02:00
|
|
|
- goos: windows
|
|
|
|
goarch: arm
|
|
|
|
goarm: 7
|
|
|
|
# BEGIN Other architectures
|
2023-07-17 10:09:02 +03:00
|
|
|
# BEGIN riscv64 & ARM64 & LOONG64
|
2021-03-02 16:46:50 +02:00
|
|
|
- goos: linux
|
|
|
|
goarch: arm64
|
|
|
|
- goos: linux
|
|
|
|
goarch: riscv64
|
2023-07-17 10:09:02 +03:00
|
|
|
- goos: linux
|
|
|
|
goarch: loong64
|
|
|
|
# END riscv64 & ARM64 & LOONG64
|
2021-03-02 16:46:50 +02:00
|
|
|
# BEGIN MIPS
|
|
|
|
- goos: linux
|
|
|
|
goarch: mips64
|
|
|
|
- goos: linux
|
|
|
|
goarch: mips64le
|
|
|
|
- goos: linux
|
|
|
|
goarch: mipsle
|
|
|
|
- goos: linux
|
|
|
|
goarch: mips
|
|
|
|
# END MIPS
|
|
|
|
# BEGIN PPC
|
|
|
|
- goos: linux
|
|
|
|
goarch: ppc64
|
|
|
|
- goos: linux
|
|
|
|
goarch: ppc64le
|
|
|
|
# END PPC
|
|
|
|
# BEGIN FreeBSD ARM
|
|
|
|
- goos: freebsd
|
|
|
|
goarch: arm64
|
|
|
|
- goos: freebsd
|
|
|
|
goarch: arm
|
|
|
|
goarm: 7
|
|
|
|
# END FreeBSD ARM
|
|
|
|
# BEGIN S390X
|
|
|
|
- goos: linux
|
|
|
|
goarch: s390x
|
|
|
|
# END S390X
|
|
|
|
# END Other architectures
|
|
|
|
# BEGIN OPENBSD ARM
|
|
|
|
- goos: openbsd
|
|
|
|
goarch: arm64
|
|
|
|
- goos: openbsd
|
|
|
|
goarch: arm
|
|
|
|
goarm: 7
|
|
|
|
# END OPENBSD ARM
|
|
|
|
fail-fast: false
|
2021-03-06 08:34:40 +02:00
|
|
|
|
|
|
|
runs-on: ubuntu-latest
|
2021-03-02 16:46:50 +02:00
|
|
|
env:
|
|
|
|
GOOS: ${{ matrix.goos }}
|
|
|
|
GOARCH: ${{ matrix.goarch }}
|
|
|
|
GOARM: ${{ matrix.goarm }}
|
|
|
|
CGO_ENABLED: 0
|
|
|
|
steps:
|
|
|
|
- name: Checkout codebase
|
2023-09-05 03:43:27 +03:00
|
|
|
uses: actions/checkout@v4
|
2021-03-02 16:46:50 +02:00
|
|
|
|
2024-07-15 12:53:40 +03:00
|
|
|
- name: Show workflow information
|
2021-03-02 16:46:50 +02:00
|
|
|
run: |
|
2024-07-15 12:53:40 +03:00
|
|
|
_NAME=${{ matrix.patch-assetname }}
|
|
|
|
[ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json)
|
2021-03-02 16:46:50 +02:00
|
|
|
echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME"
|
|
|
|
echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
|
|
|
|
|
|
|
|
- name: Set up Go
|
2023-12-07 02:20:06 +02:00
|
|
|
uses: actions/setup-go@v5
|
2021-03-02 16:46:50 +02:00
|
|
|
with:
|
2024-12-21 11:51:33 +02:00
|
|
|
go-version-file: go.mod
|
2022-02-21 16:13:35 +02:00
|
|
|
check-latest: true
|
2021-03-02 16:46:50 +02:00
|
|
|
|
|
|
|
- name: Get project dependencies
|
|
|
|
run: go mod download
|
|
|
|
|
|
|
|
- name: Build Xray
|
|
|
|
run: |
|
|
|
|
mkdir -p build_assets
|
2024-01-02 17:13:38 +02:00
|
|
|
make
|
2024-06-05 21:31:48 +03:00
|
|
|
find . -maxdepth 1 -type f -regex './\(wxray\|xray\|xray_softfloat\)\(\|.exe\)' -exec mv {} ./build_assets/ \;
|
2021-03-02 16:46:50 +02:00
|
|
|
|
2023-02-25 04:26:28 +02:00
|
|
|
- name: Restore Cache
|
2024-01-18 02:15:36 +02:00
|
|
|
uses: actions/cache/restore@v4
|
2022-12-19 03:01:56 +02:00
|
|
|
with:
|
2023-02-25 04:26:28 +02:00
|
|
|
path: resources
|
|
|
|
key: xray-geodat-
|
|
|
|
|
|
|
|
- name: Copy README.md & LICENSE
|
|
|
|
run: |
|
|
|
|
mv -f resources/* build_assets
|
|
|
|
cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
|
|
|
|
cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
|
2021-03-02 16:46:50 +02:00
|
|
|
|
|
|
|
- name: Create ZIP archive
|
2024-06-05 21:31:48 +03:00
|
|
|
if: github.event_name == 'release'
|
2021-03-02 16:46:50 +02:00
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
pushd build_assets || exit 1
|
2021-03-06 08:34:40 +02:00
|
|
|
touch -mt $(date +%Y01010000) *
|
2022-11-22 14:58:03 +02:00
|
|
|
zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip .
|
2021-03-02 16:46:50 +02:00
|
|
|
popd || exit 1
|
2022-11-22 14:58:03 +02:00
|
|
|
FILE=./Xray-${{ env.ASSET_NAME }}.zip
|
2021-03-02 16:46:50 +02:00
|
|
|
DGST=$FILE.dgst
|
|
|
|
for METHOD in {"md5","sha1","sha256","sha512"}
|
|
|
|
do
|
|
|
|
openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST
|
|
|
|
done
|
|
|
|
|
|
|
|
- name: Change the name
|
|
|
|
run: |
|
2022-11-22 14:58:03 +02:00
|
|
|
mv build_assets Xray-${{ env.ASSET_NAME }}
|
2021-03-02 16:46:50 +02:00
|
|
|
|
|
|
|
- name: Upload files to Artifacts
|
2023-12-15 02:58:43 +02:00
|
|
|
uses: actions/upload-artifact@v4
|
2021-03-02 16:46:50 +02:00
|
|
|
with:
|
2022-11-22 14:58:03 +02:00
|
|
|
name: Xray-${{ env.ASSET_NAME }}
|
2021-03-02 16:46:50 +02:00
|
|
|
path: |
|
2022-11-22 14:58:03 +02:00
|
|
|
./Xray-${{ env.ASSET_NAME }}/*
|
2021-03-02 16:46:50 +02:00
|
|
|
|
|
|
|
- name: Upload binaries to release
|
|
|
|
uses: svenstaro/upload-release-action@v2
|
|
|
|
if: github.event_name == 'release'
|
|
|
|
with:
|
|
|
|
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
2022-11-22 14:58:03 +02:00
|
|
|
file: ./Xray-${{ env.ASSET_NAME }}.zip*
|
2021-03-02 16:46:50 +02:00
|
|
|
tag: ${{ github.ref }}
|
|
|
|
file_glob: true
|