Build dcompass on various targets #1518
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Build dcompass on various targets" | |
on: | |
push: | |
schedule: | |
- cron: '0 1 * * *' | |
jobs: | |
cachix: | |
if: ((startsWith(github.event.head_commit.message, 'build:') || (github.event_name == 'schedule'))) && (needs.create-release.outputs.log-num > 0) | |
name: upload cachix | |
needs: create-release | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
# Nix Flakes doesn't work on shallow clones | |
fetch-depth: 0 | |
- uses: cachix/install-nix-action@v20 | |
- uses: cachix/cachix-action@v12 | |
with: | |
name: dcompass | |
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' | |
pushFilter: '(-source$|nixpkgs\.tar\.gz$|\.iso$|-squashfs.img$|crate-$)' | |
# Run the general flake checks | |
- run: nix flake check -vL | |
create-release: | |
if: (startsWith(github.event.head_commit.message, 'build:') || (github.event_name == 'schedule')) | |
name: Create release | |
runs-on: ubuntu-latest | |
outputs: | |
date: ${{ steps.current_time.outputs.formattedTime }} | |
log-num: ${{ steps.get_log.outputs.log-num }} | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Get current time | |
uses: 1466587594/get-current-time@v2 | |
id: current_time | |
with: | |
format: YYYYMMDD_HHmm | |
utcOffset: "+08:00" | |
- name: Get log | |
id: get_log | |
run: | | |
echo "::set-output name=log-num::$(git --no-pager log --since yesterday --pretty=format:%h%x09%an%x09%ad%x09%s --date short | grep -c '')" | |
- name: Create release | |
id: create_release | |
if: ${{steps.get_log.outputs.log-num > 0}} | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: build-${{ steps.current_time.outputs.formattedTime }} | |
release_name: Automated build ${{ steps.current_time.outputs.formattedTime }} | |
build-release: | |
name: Build dcompass for ${{ matrix.target }} | |
if: ((startsWith(github.event.head_commit.message, 'build:') || (github.event_name == 'schedule'))) && (needs.create-release.outputs.log-num > 0) | |
needs: create-release | |
strategy: | |
fail-fast: false | |
matrix: | |
# armv5te-unknown-linux-musleabi being temporarily removed due to https://github.com/antifuchs/governor/issues/89 | |
# x86_64-unknown-freebsd removed for unknown issue on link. Potentially due to missing third party library in cross environment. | |
target: [x86_64-unknown-linux-musl, x86_64-unknown-linux-gnu, armv7-unknown-linux-musleabihf, x86_64-pc-windows-gnu, x86_64-apple-darwin, aarch64-unknown-linux-musl, x86_64-unknown-netbsd, i686-unknown-linux-musl, armv5te-unknown-linux-musleabi, mips-unknown-linux-musl, mips64-unknown-linux-gnuabi64, mips64el-unknown-linux-gnuabi64, mipsel-unknown-linux-musl] | |
include: | |
- target: x86_64-unknown-netbsd | |
os: ubuntu-latest | |
- target: x86_64-unknown-linux-musl | |
os: ubuntu-latest | |
- target: x86_64-unknown-linux-gnu | |
os: ubuntu-latest | |
- target: i686-unknown-linux-musl | |
os: ubuntu-latest | |
- target: aarch64-unknown-linux-musl | |
os: ubuntu-latest | |
- target: armv7-unknown-linux-musleabihf | |
os: ubuntu-latest | |
- target: armv5te-unknown-linux-musleabi | |
os: ubuntu-latest | |
- target: x86_64-pc-windows-gnu | |
os: ubuntu-latest | |
- target: x86_64-apple-darwin | |
os: macos-latest | |
# - target: x86_64-unknown-freebsd | |
# os: ubuntu-latest | |
- target: mips-unknown-linux-musl | |
os: ubuntu-latest | |
- target: mips64-unknown-linux-gnuabi64 | |
os: ubuntu-latest | |
- target: mips64el-unknown-linux-gnuabi64 | |
os: ubuntu-latest | |
- target: mipsel-unknown-linux-musl | |
os: ubuntu-latest | |
# - target: i686-unknown-freebsd | |
# os: ubuntu-latest | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Install Nix | |
uses: cachix/install-nix-action@v20 | |
- name: Checkout | |
uses: actions/checkout@v1 | |
- name: Update data files | |
run: nix run .#update | |
- name: Install musl tools | |
if: contains(matrix.target, 'musl') | |
run: sudo apt-get install musl-tools | |
- name: Install i686 tools | |
if: contains(matrix.target, 'i686') | |
run: sudo apt-get install binutils-i686-linux-gnu | |
- name: Install mipsel tools | |
if: contains(matrix.target, 'mipsel') | |
run: sudo apt-get install binutils-mipsel-linux-gnu | |
- name: Install mips64el tools | |
if: contains(matrix.target, 'mips64el') | |
run: | | |
sudo apt-get install binutils-mips64el-linux-gnuabi64 | |
# docker build --tag cross:mips64el-unknown-linux-muslabi64 -f Dockerfile.mips64el-unknown-linux-muslabi64 https://github.com/compassd/cross.git#master:docker | |
- name: Install mips tools | |
if: contains(matrix.target, 'mips-') | |
run: sudo apt-get install binutils-mips-linux-gnu | |
- name: Install mips64 tools | |
if: contains(matrix.target, 'mips64-') | |
run: | | |
sudo apt-get install binutils-mips64-linux-gnuabi64 | |
# docker build --tag cross:mips64-unknown-linux-muslabi64 -f Dockerfile.mips64-unknown-linux-muslabi64 https://github.com/compassd/cross.git#master:docker | |
- name: Install aarch64 tools | |
if: contains(matrix.target, 'aarch64') | |
run: sudo apt-get install binutils-aarch64-linux-gnu | |
- name: Install arm tools | |
if: contains(matrix.target, 'arm') | |
run: sudo apt-get install binutils-arm-linux-gnueabihf | |
- uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
target: ${{ matrix.target }} | |
- uses: actions-rs/install@v0.1 | |
with: | |
crate: cross | |
version: latest | |
use-tool-cache: true | |
- name: Cargo update | |
run: cargo update | |
- uses: actions/cache@v2 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
target | |
key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
- name: Build full | |
run: | | |
cross build --manifest-path ./dcompass/Cargo.toml --release --locked --target ${{ matrix.target }} --features "geoip-maxmind" | |
if [[ "${{ matrix.target }}" == *"windows"* ]] | |
then | |
cp ./target/${{ matrix.target }}/release/dcompass.exe ./dcompass-${{ matrix.target }}-full.exe | |
else | |
cp ./target/${{ matrix.target }}/release/dcompass ./dcompass-${{ matrix.target }}-full | |
fi | |
cross build --manifest-path ./dcompass/Cargo.toml --release --locked --target ${{ matrix.target }} --features "geoip-cn" | |
if [[ "${{ matrix.target }}" == *"windows"* ]] | |
then | |
cp ./target/${{ matrix.target }}/release/dcompass.exe ./dcompass-${{ matrix.target }}.exe | |
else | |
cp ./target/${{ matrix.target }}/release/dcompass ./dcompass-${{ matrix.target }} | |
fi | |
- name: Strip x86 | |
if: contains(matrix.target, 'x86') | |
shell: bash | |
run: | | |
if [[ "${{ matrix.target }}" == "x86_64-pc-windows-gnu" ]] | |
then | |
strip ./dcompass-${{ matrix.target }}-full.exe | |
strip ./dcompass-${{ matrix.target }}.exe | |
else | |
strip ./dcompass-${{ matrix.target }}-full | |
strip ./dcompass-${{ matrix.target }} | |
fi | |
- name: Strip arm | |
if: contains(matrix.target, 'arm') | |
shell: bash | |
run: | | |
arm-linux-gnueabihf-strip ./dcompass-${{ matrix.target }}-full | |
arm-linux-gnueabihf-strip ./dcompass-${{ matrix.target }} | |
- name: Strip mipsel | |
if: contains(matrix.target, 'mipsel') | |
shell: bash | |
run: | | |
mipsel-linux-gnu-strip ./dcompass-${{ matrix.target }}-full | |
mipsel-linux-gnu-strip ./dcompass-${{ matrix.target }} | |
- name: Strip mips64el | |
if: contains(matrix.target, 'mips64el') | |
shell: bash | |
run: | | |
mips64el-linux-gnuabi64-strip ./dcompass-${{ matrix.target }}-full | |
mips64el-linux-gnuabi64-strip ./dcompass-${{ matrix.target }} | |
- name: Strip mips | |
if: contains(matrix.target, 'mips-') | |
shell: bash | |
run: | | |
mips-linux-gnu-strip ./dcompass-${{ matrix.target }}-full | |
mips-linux-gnu-strip ./dcompass-${{ matrix.target }} | |
- name: Strip mips64 | |
if: contains(matrix.target, 'mips64-') | |
shell: bash | |
run: | | |
mips64-linux-gnuabi64-strip ./dcompass-${{ matrix.target }}-full | |
mips64-linux-gnuabi64-strip ./dcompass-${{ matrix.target }} | |
- name: Strip i686 | |
if: contains(matrix.target, 'i686') | |
shell: bash | |
run: | | |
i686-linux-gnu-strip ./dcompass-${{ matrix.target }}-full | |
i686-linux-gnu-strip ./dcompass-${{ matrix.target }} | |
- name: Strip aarch64 | |
if: contains(matrix.target, 'aarch64') | |
shell: bash | |
run: | | |
aarch64-linux-gnu-strip ./dcompass-${{ matrix.target }}-full | |
aarch64-linux-gnu-strip ./dcompass-${{ matrix.target }} | |
# - name: Package | |
# shell: bash | |
# run: | | |
# if [[ "${{ matrix.target }}" == "x86_64-pc-windows-gnu" ]] | |
# then | |
# upx ./dcompass-${{ matrix.target }}-full.exe || true | |
# upx ./dcompass-${{ matrix.target }}.exe || true | |
# else | |
# upx ./dcompass-${{ matrix.target }}-full || true | |
# upx ./dcompass-${{ matrix.target }} || true | |
# fi | |
- name: Echo body | |
if: ${{ matrix.target == 'x86_64-unknown-linux-musl' }} | |
run: git --no-pager log --since yesterday --pretty=format:%h%x09%an%x09%ad%x09%s --date short > changelog.txt | |
- name: Publish | |
if: ${{ matrix.target == 'x86_64-unknown-linux-musl' }} | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: 'dcompass*' | |
body_path: changelog.txt | |
tag_name: build-${{ needs.create-release.outputs.date }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish (no notes) | |
if: ${{ matrix.target != 'x86_64-unknown-linux-musl' }} | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: 'dcompass*' | |
tag_name: build-${{ needs.create-release.outputs.date }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
remove-release: | |
name: Clean up release(s) | |
if: (startsWith(github.event.head_commit.message, 'build:') || (github.event_name == 'schedule')) | |
needs: build-release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clean-up releases | |
uses: dev-drprasad/delete-older-releases@v0.1.0 | |
with: | |
keep_latest: 7 | |
delete_tags: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |