Skip to content

Commit

Permalink
Merge pull request #61 from noahmmcgivern/github-workflows
Browse files Browse the repository at this point in the history
Github workflows
  • Loading branch information
cutler-scott-newrelic committed Dec 6, 2023
2 parents c13d4a8 + b6e9119 commit a7156f1
Show file tree
Hide file tree
Showing 11 changed files with 337 additions and 94 deletions.
217 changes: 217 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
name: Release

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
workflow_call:
secrets:
DOCKER_PASSWORD:
required: true

permissions:
contents: write

env:
PROJECT_NAME: rustyhogs

jobs:
dist-binaries:
name: Dist Binaries
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
build: [x86_64-linux, x86_64-macos, x86_64-windows]
include:
- build: x86_64-linux
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-gnu
cross: false
- build: x86_64-macos
os: macos-latest
rust: stable
target: x86_64-apple-darwin
cross: false
# - build: aarch64-macos
# os: macos-13-xlarge
# rust: stable
# target: aarch64-apple-darwin
# cross: false
- build: x86_64-windows
os: windows-2019
rust: stable
target: x86_64-pc-windows-msvc
cross: false
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Install ${{ matrix.rust }}-${{ matrix.target }} toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
override: true
- name: Build release binaries
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.cross }}
command: build
args: --release --target ${{ matrix.target }}
- name: Build archive
shell: bash
run: |
mkdir dist
ls -lah target/${{ matrix.target }}/release
if [[ ${{ matrix.build }} =~ "windows" ]]; then
echo "${{ matrix.build }}: using .exe extension"
exe=".exe"
fi
cp ./target/${{ matrix.target }}/release/*_hog$exe dist
- uses: actions/upload-artifact@v3
with:
name: bins-${{ matrix.build }}
path: dist
dist-lambda:
name: Dist Lambda
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Install stable-x86_64-unknown-linux-musl toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: x86_64-unknown-linux-musl
override: true
- name: Build release binaries
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --release --target x86_64-unknown-linux-musl
- name: Build archive
shell: bash
run: |
mkdir dist
cp ./target/x86_64-unknown-linux-musl/release/*_lambda dist
- uses: actions/upload-artifact@v3
with:
name: bins-lambda
path: dist
dist-docker:
name: Dist Docker
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Get tag name
id: tagname
run: |
name=dev
echo $GITHUB_REF
if [[ $GITHUB_REF == refs/tags/v* ]]; then
name=${GITHUB_REF:10}
fi
echo "tag=${name//v}" >> "$GITHUB_OUTPUT"
- name: Build Docker Images
shell: bash
run: make docker-build VERSION=${{ steps.tagname.outputs.tag }}
- name: Save Docker Images
shell: bash
run: make docker-save VERSION=${{ steps.tagname.outputs.tag }}
- uses: actions/upload-artifact@v3
with:
name: docker
path: images.tar
publish:
name: Publish Archive
needs: [dist-binaries, dist-lambda, dist-docker]
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v3
- name: List binaries
run: ls -lah bins-*
- name: Get tag name
id: tagname
run: |
name=dev
echo $GITHUB_REF
if [[ $GITHUB_REF == refs/tags/v* ]]; then
name=${GITHUB_REF:10}
fi
echo "tagname=${name}" >> "$GITHUB_OUTPUT"
echo "tag=${name//v}" >> "$GITHUB_OUTPUT"
- name: Build archive
shell: bash
run: |
set -ex
rm -rf tmp
mkdir tmp
mkdir dist
for dir in bins-*;
do
platform=${dir#"bins-"}
pkgname=$PROJECT_NAME-${{ steps.tagname.outputs.tag }}-$platform
ls -lah $dir
chmod +x $dir/*
mkdir tmp/$pkgname
mv $dir/* tmp/$pkgname
if [[ $platform =~ "windows" ]]; then
(cd tmp && zip -r ../dist/$pkgname.zip $pkgname)
else
tar czf dist/$pkgname.tar.gz -C tmp $pkgname
fi
done
- name: Add scripts to archive
shell: bash
run: |
pkgname=$PROJECT_NAME-${{ steps.tagname.outputs.tag }}-scripts
tar czf dist/$pkgname.tar.gz scripts
- name: Release archive
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: dist/*
file_glob: true
tag: ${{ steps.tagname.outputs.tagname }}
overwrite: true
publish-docker:
name: Publish Docker Images
needs: [dist-binaries, dist-lambda, dist-docker]
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: docker
- name: Load Docker Images
shell: bash
run: make docker-load
- name: List Docker Images
shell: bash
run: docker images | grep hog
- name: Get tag name
id: tagname
run: |
name=dev
echo $GITHUB_REF
if [[ $GITHUB_REF == refs/tags/v* ]]; then
name=${GITHUB_REF:10}
fi
echo "tag=${name//v}" >> "$GITHUB_OUTPUT"
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: wetfeet2000
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Publish Docker Images
run: make docker-publish VERSION=${{ steps.tagname.outputs.tag }}
71 changes: 71 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Testing

on:
pull_request:
branches: [master]

env:
CARGO_TERM_COLOR: always

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Compile Check
run: cargo check
- name: Format check
run: cargo fmt --all --check
- name: Lint
run: cargo clippy
test:
name: Test
needs: lint
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
build: [x86_64-linux, x86_64-linux-musl, x86_64-macos, x86_64-windows]
include:
- build: x86_64-linux
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-gnu
cross: false
- build: x86_64-linux-musl
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-musl
cross: true
- build: x86_64-macos
os: macos-latest
rust: stable
target: x86_64-apple-darwin
cross: false
# - build: aarch64-macos
# os: macos-13-xlarge
# rust: stable
# target: aarch64-apple-darwin
# cross: false
- build: x86_64-windows
os: windows-2019
rust: stable
target: x86_64-pc-windows-msvc
cross: false
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Install ${{ matrix.rust }}-${{ matrix.target }} toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
override: true
- name: Test
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.cross }}
command: test
args: --release --target ${{ matrix.target }} --verbose
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

16 changes: 0 additions & 16 deletions Dockerfile

This file was deleted.

5 changes: 5 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM rust:latest
RUN mkdir -p /build
WORKDIR /build
COPY . /build/
RUN cargo build --release
6 changes: 6 additions & 0 deletions Dockerfile.hog
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM rust-builder as builder
FROM debian:bookworm-slim
ARG HOG="choctaw"
ENV HOG_BIN="${HOG}_hog"
COPY --from=builder /build/target/release/$HOG_BIN /usr/local/bin/
ENTRYPOINT /usr/local/bin/$HOG_BIN
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
null:
@:

docker-build: check-version
@echo Building Rusty Hogs version: $(VERSION)
docker build --tag rust-builder -f Dockerfile.build .
docker build --tag wetfeet2000/ankamali_hog:$(VERSION) --build-arg HOG=ankamali -f Dockerfile.hog .
docker build --tag wetfeet2000/berkshire_hog:$(VERSION) --build-arg HOG=berkshire -f Dockerfile.hog .
docker build --tag wetfeet2000/choctaw_hog:$(VERSION) --build-arg HOG=choctaw -f Dockerfile.hog .
docker build --tag wetfeet2000/duroc_hog:$(VERSION) --build-arg HOG=duroc -f Dockerfile.hog .
docker build --tag wetfeet2000/essex_hog:$(VERSION) --build-arg HOG=essex -f Dockerfile.hog .
docker build --tag wetfeet2000/gottingen_hog:$(VERSION) --build-arg HOG=gottingen -f Dockerfile.hog .
docker build --tag wetfeet2000/hante_hog:$(VERSION) --build-arg HOG=hante -f Dockerfile.hog .

docker-save: check-version
docker image save -o images.tar \
wetfeet2000/ankamali_hog:$(VERSION) \
wetfeet2000/berkshire_hog:$(VERSION) \
wetfeet2000/choctaw_hog:$(VERSION) \
wetfeet2000/duroc_hog:$(VERSION) \
wetfeet2000/essex_hog:$(VERSION) \
wetfeet2000/gottingen_hog:$(VERSION) \
wetfeet2000/hante_hog:$(VERSION)

docker-load:
docker load -i images.tar

docker-publish: check-version
docker push wetfeet2000/ankamali_hog:$(VERSION)
docker push wetfeet2000/berkshire_hog:$(VERSION)
docker push wetfeet2000/choctaw_hog:$(VERSION)
docker push wetfeet2000/duroc_hog:$(VERSION)
docker push wetfeet2000/essex_hog:$(VERSION)
docker push wetfeet2000/gottingen_hog:$(VERSION)
docker push wetfeet2000/hante_hog:$(VERSION)

check-version:
@if test ! $(VERSION); then echo "VERSION is undefined"; exit 1; fi
14 changes: 0 additions & 14 deletions build_docker.sh

This file was deleted.

Loading

0 comments on commit a7156f1

Please sign in to comment.