mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
Updated build workflow for CGO cross compile.
This commit is contained in:
parent
bee624b357
commit
adf1f07394
2 changed files with 56 additions and 16 deletions
5
.github/build/compiler_arch.json
vendored
Normal file
5
.github/build/compiler_arch.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"386": {"linux": "i686"},
|
||||||
|
"amd64": {"linux": "x86_64", "darwin": "o64"},
|
||||||
|
"arm64": {"linux": "aarch64", "darwin": "oa64"}
|
||||||
|
}
|
67
.github/workflows/build.yml
vendored
67
.github/workflows/build.yml
vendored
|
@ -1,4 +1,4 @@
|
||||||
name: Build and Publish
|
name: Build
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
@ -37,9 +37,9 @@ jobs:
|
||||||
- name: Set up nodejs
|
- name: Set up nodejs
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: '14.x'
|
node-version: '16.x'
|
||||||
cache: 'yarn'
|
cache: 'yarn'
|
||||||
cache-dependency-path: '**/yarn.lock'
|
cache-dependency-path: 'frontend/yarn.lock'
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn install
|
run: yarn install
|
||||||
|
@ -73,7 +73,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
files: frontend-dist.tar.gz
|
files: frontend-dist.tar.gz
|
||||||
|
|
||||||
build_backend:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build_frontend
|
needs: build_frontend
|
||||||
strategy:
|
strategy:
|
||||||
|
@ -85,9 +85,12 @@ jobs:
|
||||||
- goarch: 386
|
- goarch: 386
|
||||||
goos: darwin
|
goos: darwin
|
||||||
env:
|
env:
|
||||||
|
CGO_ENABLED: 1
|
||||||
GOOS: ${{ matrix.goos }}
|
GOOS: ${{ matrix.goos }}
|
||||||
GOARCH: ${{ matrix.goarch }}
|
GOARCH: ${{ matrix.goarch }}
|
||||||
DIST: nginx-ui-${{ matrix.goos }}-${{ matrix.goarch }}
|
DIST: nginx-ui-${{ matrix.GOOS }}-${{ matrix.GOARCH }}
|
||||||
|
outputs:
|
||||||
|
dist: ${{ env.DIST }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
@ -107,6 +110,38 @@ jobs:
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-${{ env.GOOS }}-${{ env.GOARCH }}-go-
|
${{ runner.os }}-${{ env.GOOS }}-${{ env.GOARCH }}-go-
|
||||||
|
|
||||||
|
- name: Setup compiler environment
|
||||||
|
id: info
|
||||||
|
run: |
|
||||||
|
export _ARCH=$(jq ".[\"$GOARCH\"].$GOOS" -r < .github/build/compiler_arch.json)
|
||||||
|
echo "::set-output name=ARCH_NAME::$_ARCH"
|
||||||
|
|
||||||
|
- name: Install musl cross compiler
|
||||||
|
if: env.GOOS == 'linux'
|
||||||
|
uses: Lesmiscore/musl-cross-compilers@v0.5
|
||||||
|
id: musl
|
||||||
|
with:
|
||||||
|
target: ${{ steps.info.outputs.ARCH_NAME }}-linux-musl
|
||||||
|
|
||||||
|
- name: Post install musl cross compiler
|
||||||
|
if: env.GOOS == 'linux'
|
||||||
|
run: |
|
||||||
|
echo "PATH=${{ steps.musl.outputs.path }}:$PATH" >> $GITHUB_ENV
|
||||||
|
echo "CC=${{ steps.info.outputs.ARCH_NAME }}-linux-musl-gcc" >> $GITHUB_ENV
|
||||||
|
echo "CXX=${{ steps.info.outputs.ARCH_NAME }}-linux-musl-g++" >> $GITHUB_ENV
|
||||||
|
echo "LD_FLAGS=--extldflags '-static'" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Install darwin cross compiler
|
||||||
|
if: env.GOOS == 'darwin'
|
||||||
|
run: |
|
||||||
|
curl -L https://github.com/Hintay/crossosx/releases/latest/download/crossosx.tar.zst -o crossosx.tar.zst
|
||||||
|
tar xvaf crossosx.tar.zst
|
||||||
|
echo "LD_LIBRARY_PATH=$(pwd)/crossosx/lib/" >> $GITHUB_ENV
|
||||||
|
echo "PATH=$(pwd)/crossosx/bin/:$PATH" >> $GITHUB_ENV
|
||||||
|
echo "CC=${{ steps.info.outputs.ARCH_NAME }}-clang" >> $GITHUB_ENV
|
||||||
|
echo "CXX=${{ steps.info.outputs.ARCH_NAME }}-clang++" >> $GITHUB_ENV
|
||||||
|
echo "LD_FLAGS=-s -w" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Download frontend artifacts
|
- name: Download frontend artifacts
|
||||||
uses: actions/download-artifact@v2
|
uses: actions/download-artifact@v2
|
||||||
with:
|
with:
|
||||||
|
@ -116,7 +151,7 @@ jobs:
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
go build -o dist/nginx-ui -v main.go
|
go build -ldflags "$LD_FLAGS" -o dist/nginx-ui -v main.go
|
||||||
|
|
||||||
- name: Archive backend artifacts
|
- name: Archive backend artifacts
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
|
@ -124,14 +159,14 @@ jobs:
|
||||||
name: ${{ env.DIST }}
|
name: ${{ env.DIST }}
|
||||||
path: dist/nginx-ui
|
path: dist/nginx-ui
|
||||||
|
|
||||||
- name: Prepare publish
|
- name: Prepare publish
|
||||||
if: github.event_name == 'release'
|
if: github.event_name == 'release'
|
||||||
run: |
|
run: |
|
||||||
cp README*.md ./dist
|
cp README*.md ./dist
|
||||||
find dist -printf '%P\n' | tar -C dist --no-recursion -zcvf ${{ env.DIST }}.tar.gz -T -
|
find dist -printf '%P\n' | tar -C dist --no-recursion -zcvf ${{ env.DIST }}.tar.gz -T -
|
||||||
|
|
||||||
- name: Publish
|
- name: Publish
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
if: github.event_name == 'release'
|
if: github.event_name == 'release'
|
||||||
with:
|
with:
|
||||||
files: ${{ env.DIST }}.tar.gz
|
files: ${{ env.DIST }}.tar.gz
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue