mirror of
https://github.com/heiher/natmap.git
synced 2026-05-06 21:51:26 +08:00
416 lines
12 KiB
YAML
416 lines
12 KiB
YAML
name: "Build"
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
pull_request:
|
|
release:
|
|
types:
|
|
- published
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
source:
|
|
name: Source
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
BRANCH_NAME: ${{ github.base_ref || github.ref_name }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
submodules: true
|
|
- name: Gen Source
|
|
run: |
|
|
REV_ID=$(git tag --points-at HEAD)
|
|
if [ -z "${REV_ID}" ]; then
|
|
REV_ID=$(git rev-parse --short HEAD)
|
|
fi
|
|
mkdir -p natmap-${{ env.BRANCH_NAME }}
|
|
git ls-files --recurse-submodules | tar c -O -T- | tar x -C natmap-${{ env.BRANCH_NAME }}
|
|
echo ${REV_ID} > natmap-${{ env.BRANCH_NAME }}/.version
|
|
tar cJf natmap-${{ env.BRANCH_NAME }}.tar.xz natmap-${{ env.BRANCH_NAME }}
|
|
- name: Upload source
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: natmap-${{ env.BRANCH_NAME }}.tar.xz
|
|
path: natmap-${{ env.BRANCH_NAME }}.tar.xz
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
linux:
|
|
name: Linux
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
include:
|
|
- name: arm64
|
|
tool: aarch64-unknown-linux-musl
|
|
- name: arm32
|
|
tool: arm-unknown-linux-musleabi
|
|
- name: arm32hf
|
|
tool: arm-unknown-linux-musleabihf
|
|
- name: arm32v7
|
|
tool: armv7-unknown-linux-musleabi
|
|
- name: arm32v7hf
|
|
tool: armv7-unknown-linux-musleabihf
|
|
- name: i586
|
|
tool: i586-unknown-linux-musl
|
|
- name: i686
|
|
tool: i686-unknown-linux-musl
|
|
- name: loong64
|
|
tool: loongarch64-unknown-linux-musl
|
|
- name: m68k
|
|
tool: m68k-unknown-linux-musl
|
|
- name: microblazeel
|
|
tool: microblazeel-xilinx-linux-musl
|
|
- name: microblaze
|
|
tool: microblaze-xilinx-linux-musl
|
|
- name: mips64el
|
|
tool: mips64el-unknown-linux-musl
|
|
- name: mips64
|
|
tool: mips64-unknown-linux-musl
|
|
- name: mips32el
|
|
tool: mipsel-unknown-linux-musl
|
|
- name: mips32elsf
|
|
tool: mipsel-unknown-linux-muslsf
|
|
- name: mips32
|
|
tool: mips-unknown-linux-musl
|
|
- name: mips32sf
|
|
tool: mips-unknown-linux-muslsf
|
|
- name: powerpc64
|
|
tool: powerpc64-unknown-linux-musl
|
|
- name: powerpc
|
|
tool: powerpc-unknown-linux-musl
|
|
- name: riscv32
|
|
tool: riscv32-unknown-linux-musl
|
|
- name: riscv64
|
|
tool: riscv64-unknown-linux-musl
|
|
- name: s390x
|
|
tool: s390x-ibm-linux-musl
|
|
- name: sh4
|
|
tool: sh4-multilib-linux-musl
|
|
- name: x86_64
|
|
tool: x86_64-unknown-linux-musl
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
submodules: true
|
|
- name: Build ${{ matrix.name }}
|
|
run: |
|
|
sudo mkdir -p /opt/x-tools
|
|
wget https://github.com/cross-tools/musl-cross/releases/download/20250520/${{ matrix.tool }}.tar.xz
|
|
sudo tar xf ${{ matrix.tool }}.tar.xz -C /opt/x-tools
|
|
make CROSS_PREFIX=/opt/x-tools/${{ matrix.tool }}/bin/${{ matrix.tool }}- CFLAGS=${{ matrix.env.CFLAGS }} ENABLE_STATIC=1 -j`nproc`
|
|
cp bin/natmap natmap-linux-${{ matrix.name }}
|
|
- name: Upload ${{ matrix.name }}
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: natmap-linux-${{ matrix.name }}
|
|
path: natmap-linux-${{ matrix.name }}
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
windows:
|
|
name: Windows
|
|
runs-on: windows-latest
|
|
defaults:
|
|
run:
|
|
shell: cmd
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
submodules: true
|
|
- name: Setup MSYS2
|
|
uses: msys2/setup-msys2@v2
|
|
with:
|
|
msystem: MSYS
|
|
location: D:\msys2
|
|
update: true
|
|
install: >-
|
|
gcc
|
|
git
|
|
make
|
|
wget
|
|
zip
|
|
- name: Build
|
|
shell: msys2 {0}
|
|
run: |
|
|
export MSYS=winsymlinks:native
|
|
git clone --depth=1 --recursive file://`pwd` work; cd work
|
|
make LFLAGS="-lmsys-2.0 -lws2_32" -j`nproc`
|
|
mkdir natmap
|
|
cp bin/natmap* natmap
|
|
wget -P natmap https://github.com/heiher/msys2/releases/latest/download/msys-2.0.dll
|
|
zip -r ../natmap-win64.zip natmap
|
|
- name: Upload ${{ matrix.name }}
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: natmap-win64.zip
|
|
path: natmap-win64.zip
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
macos:
|
|
name: macOS
|
|
runs-on: macos-latest
|
|
strategy:
|
|
matrix:
|
|
include:
|
|
- name: arm64
|
|
flags: -arch arm64 -mmacosx-version-min=11.0
|
|
- name: x86_64
|
|
flags: -arch x86_64 -mmacosx-version-min=10.6
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
submodules: true
|
|
- name: Build ${{ matrix.name }}
|
|
run: |
|
|
make CC=clang CFLAGS="${{ matrix.flags }}" LFLAGS="${{ matrix.flags }}" -j $(sysctl -n hw.logicalcpu)
|
|
cp bin/natmap natmap-darwin-${{ matrix.name }}
|
|
- name: Upload ${{ matrix.name }}
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: natmap-darwin-${{ matrix.name }}
|
|
path: natmap-darwin-${{ matrix.name }}
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
freebsd:
|
|
name: FreeBSD
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
submodules: true
|
|
- name: Build
|
|
uses: vmactions/freebsd-vm@v1
|
|
with:
|
|
usesh: true
|
|
prepare: |
|
|
pkg install -y gmake gcc
|
|
run: |
|
|
gmake
|
|
cp bin/natmap natmap-freebsd-x86_64
|
|
- name: Upload
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: natmap-freebsd-x86_64
|
|
path: natmap-freebsd-x86_64
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
release:
|
|
name: Release
|
|
runs-on: ubuntu-latest
|
|
needs:
|
|
- source
|
|
- linux
|
|
- windows
|
|
- macos
|
|
- freebsd
|
|
if: github.event_name == 'release'
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
- name: Download artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
path: release
|
|
pattern: "natmap-*"
|
|
merge-multiple: true
|
|
- name: Upload artifacts
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
for i in release/natmap-*; do
|
|
gh release upload ${{ github.event.release.tag_name }} $i
|
|
done
|
|
|
|
android:
|
|
name: Android
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name != 'release'
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
submodules: true
|
|
- name: Prepare
|
|
run: |
|
|
wget https://dl.google.com/android/repository/android-ndk-r27b-linux.zip
|
|
unzip android-ndk-r27b-linux.zip
|
|
ln -sf . jni
|
|
- name: Build
|
|
run: |
|
|
./android-ndk-r27b/ndk-build
|
|
|
|
llvm:
|
|
name: LLVM
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name != 'release'
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 1
|
|
submodules: true
|
|
- name: Prepare
|
|
run: |
|
|
sudo apt install -y clang
|
|
- name: Build
|
|
run: |
|
|
make CC=clang ENABLE_STATIC=1 -j`nproc`
|
|
|
|
docker-prepare:
|
|
needs: linux
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
repo_name_lc: ${{ steps.set-repo.outputs.repo_name_lc }}
|
|
steps:
|
|
- name: Set lowercase repo name
|
|
id: set-repo
|
|
run: |
|
|
REPO_NAME_LC=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
|
|
echo "repo_name_lc=$REPO_NAME_LC" >> $GITHUB_OUTPUT
|
|
|
|
docker-build-and-push:
|
|
needs: docker-prepare
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
include:
|
|
- arch: amd64
|
|
natmap_arch: x86_64
|
|
- arch: arm64
|
|
natmap_arch: arm64
|
|
- arch: arm
|
|
natmap_arch: arm32v7
|
|
- arch: riscv64
|
|
natmap_arch: riscv64
|
|
- arch: s390x
|
|
natmap_arch: s390x
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: docker/setup-buildx-action@v3
|
|
with:
|
|
driver: docker-container
|
|
platforms: linux/${{ matrix.arch }}
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Download built arch artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
pattern: natmap-linux-${{matrix.natmap_arch}}
|
|
path: ./tmp/artifact
|
|
|
|
- name: Build and push platform-specific image
|
|
id: build
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./docker/Dockerfile
|
|
platforms: linux/${{ matrix.arch }}
|
|
outputs: type=image,name=ghcr.io/${{ needs.docker-prepare.outputs.repo_name_lc }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
|
|
build-args: |
|
|
NATMAP_ARCH=${{ matrix.natmap_arch }}
|
|
provenance: false
|
|
sbom: false
|
|
|
|
- name: Export Digest
|
|
if: github.event_name != 'pull_request'
|
|
run: |
|
|
mkdir -p /tmp/digests
|
|
digest="${{ steps.build.outputs.digest }}"
|
|
touch "/tmp/digests/${digest#sha256:}"
|
|
ls -l /tmp/digests/
|
|
|
|
- name: Upload Digest
|
|
uses: actions/upload-artifact@v4
|
|
if: github.event_name != 'pull_request'
|
|
with:
|
|
name: docker-digest-${{ matrix.arch }}
|
|
path: /tmp/digests/*
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
docker-merge:
|
|
needs: [docker-prepare, docker-build-and-push]
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name != 'pull_request'
|
|
steps:
|
|
- name: Download Digests
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
path: /tmp/digests
|
|
pattern: docker-digest-*
|
|
merge-multiple: true
|
|
|
|
- name: Prepare Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Format Docker Image Meta
|
|
uses: docker/metadata-action@v5
|
|
id: docker_meta
|
|
with:
|
|
images: ghcr.io/${{ needs.docker-prepare.outputs.repo_name_lc }}
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=raw,value=nightly,enable={{is_default_branch}}
|
|
type=ref,event=tag
|
|
- name: Create Manifest List and Push
|
|
working-directory: /tmp/digests
|
|
run: |
|
|
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
|
|
$(printf 'ghcr.io/${{ needs.docker-prepare.outputs.repo_name_lc }}@sha256:%s ' *)
|
|
- name: Inspect image
|
|
run: |
|
|
docker buildx imagetools inspect ghcr.io/${{ needs.docker-prepare.outputs.repo_name_lc }}:${{ steps.docker_meta.outputs.version }}
|
|
|
|
- name: Delete current run's built artifacts
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
RUN_ID: ${{ github.run_id }}
|
|
run: |
|
|
sudo apt-get update && sudo apt-get install -y gh
|
|
echo "Deleting docker-digests artifacts for run ID: $RUN_ID"
|
|
|
|
gh api \
|
|
"repos/${{ github.repository }}/actions/runs/$RUN_ID/artifacts" \
|
|
-q '.artifacts[] | select(.name | startswith("docker-digest")) | .id' |
|
|
while read ARTIFACT_ID; do
|
|
echo "Deleting artifact ID: $ARTIFACT_ID"
|
|
gh api --method DELETE "repos/${{ github.repository }}/actions/artifacts/$ARTIFACT_ID"
|
|
done
|