Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: builds, packages, pushing contains to ghcr #360

Merged
merged 3 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 188 additions & 0 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
name: ⚃ Builds

on:
workflow_dispatch:
inputs:
force-builds:
required: true
type: boolean
description: Publish Builds at Anytime

release:
types: [published]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
binary-builds:
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-unknown-linux-gnu
- target: aarch64-unknown-linux-musl
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-unknown-linux-gnu
- target: x86_64-unknown-linux-musl
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: x86_64-unknown-freebsd

permissions:
contents: write

timeout-minutes: 60
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install musl-tools
run: sudo apt update && sudo apt install -y musl-dev musl-tools
if: matrix.target == 'x86_64-unknown-linux-musl' || matrix.target == 'aarch64-unknown-linux-musl'

- name: Cache Project
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
shared-key: check-${{ matrix.target }}-${{ matrix.os }}

- name: Install Rust Toolchain
id: toolchain
uses: dtolnay/rust-toolchain@stable

- name: Override rust-toolchain.toml
run: rustup override set ${{steps.toolchain.outputs.name}}

- name: cross-build
uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.target }}

- name: crt-static
run: echo "RUSTFLAGS=${RUSTFLAGS} -C target-feature=+crt-static" >>"${GITHUB_ENV}"
if: endsWith(matrix.target, 'windows-msvc')

- name: Publish Binary in Release
uses: taiki-e/upload-rust-binary-action@v1
with:
bin: homestar
target: ${{ matrix.target }}
tar: all
zip: windows
include: LICENSE,README.md
token: ${{ secrets.GITHUB_TOKEN }}

build-packages:
runs-on: ubuntu-latest

env:
LINUX_TARGET: x86_64-unknown-linux-musl

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Cache Project
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
shared-key: check-${{ env.LINUX_TARGET }}-ubuntu-latest

- name: Install musl-tools
run: sudo apt update && sudo apt install -y musl-dev musl-tools

- name: Install cargo-deb
uses: taiki-e/cache-cargo-install-action@v1
with:
tool: cargo-deb

- name: Install cargo-generate-rpm
uses: taiki-e/cache-cargo-install-action@v1
with:
tool: cargo-generate-rpm

- name: Create .deb
run: cargo deb -p homestar-runtime --target ${{env.LINUX_TARGET}}

- name: Create .rpm
run: cargo generate-rpm

- name: Publish Release Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.target }}
path: |
target/generate-rpm/
target/${{env.LINUX_TARGET}}/debian/
if-no-files-found: error

- name: Publish Package in Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
target/${{env.LINUX_TARGET}}/debian/*.deb
target/generate-rpm/*.rpm

# TODO: brew formula (Macs), cargo-wix (Windows Installs), cargo-aur (Arch)

docker-build:
runs-on: ubuntu-latest

env:
DOCKER_BUILDKIT: '1'
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

permissions:
contents: read
id-token: write
packages: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Setup QEMU
uses: docker/setup-qemu-action@v3

- name: Setup Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: "--debug"

- name: Metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern=v{{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest
type=sha

- name: Docker Build & Push
uses: docker/build-push-action@v5
with:
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
cache-to: type=inline
file: docker/Dockerfile
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
7 changes: 5 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ jobs:
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov

- name: Generate Code Coverage
run: cargo llvm-cov --all-features --workspace --doctests --lcov --output-path lcov.info
- name: Install cargo-nextest
uses: taiki-e/install-action@nextest

- name: Generate code coverage (nextest)
run: cargo llvm-cov nextest --all-features --workspace --profile=ci --lcov --output-path lcov.info

- name: Upload to codecov.io
uses: codecov/codecov-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
cache-to: type=gha,mode=max
file: docker/Dockerfile
context: .
platforms: linux/amd64
platforms: linux/amd64,linux/arm64
push: false
tags: |
${{ github.repository_owner }}/homestar:latest
19 changes: 19 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[build.env]
passthrough = [
"CARGO_INCREMENTAL",
"RUST_BACKTRACE",
"CARGO_TERM_COLOR",
"RUSTFLAGS",
]

[target.x86_64-unknown-linux-musl]
image = "burntsushi/cross:x86_64-unknown-linux-musl"

[target.aarch64-unknown-linux-musl]
image = "burntsushi/cross:aarch64-unknown-linux-gnu"

[target.x86_64-apple-darwin]
image = "freeznet/x86_64-apple-darwin-cross:11.3"

[target.aarch64-apple-darwin]
image = "freeznet/aarch64-apple-darwin-cross:11.3"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
If you're looking to help develop `homestar`, please dive right into our
[development](./DEVELOPMENT.md) guide.

Otherwise, the easiest way to get started and "see" `homestar` in action is to
Otherwise, the easiest way to get started and see `homestar` in action is to
follow-along and run our image-processing
[websocket relay](./examples/websocket-relay) example, which integrates
`homestar` with a browser application to run a
Expand Down
3 changes: 1 addition & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ ENTRYPOINT ["/bin/bash"]
# cache depencies
RUN mkdir .cargo
RUN cargo vendor > .cargo/config
RUN --mount=type=cache,target=$CARGO_HOME/registry \
cargo install diesel_cli --no-default-features --features "sqlite-bundled"
RUN cargo install diesel_cli --no-default-features --features "sqlite-bundled"
RUN diesel setup --database-url $DATABASE_URL
RUN diesel migration run --migration-dir ./homestar-runtime/migrations
RUN --mount=type=cache,id=cargo,target=$CARGO_HOME/registry \
Expand Down
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@

rust-toolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override {
extensions = ["cargo" "clippy" "rustfmt" "rust-src" "rust-std"];
targets = ["wasm32-unknown-unknown" "wasm32-wasi"];
targets = [
"wasm32-unknown-unknown"
"wasm32-wasi"
"x86_64-apple-darwin"
"aarch64-apple-darwin"
"x86_64-unknown-linux-musl"
"aarch64-unknown-linux-musl"
];
};

nightly-rustfmt = pkgs.rust-bin.nightly.latest.rustfmt;
Expand All @@ -45,6 +52,8 @@

cargo-installs = with pkgs; [
cargo-deny
cargo-deb
cargo-cross
cargo-expand
cargo-nextest
cargo-outdated
Expand All @@ -53,6 +62,7 @@
cargo-unused-features
cargo-udeps
cargo-watch
rustup
twiggy
wasm-tools
];
Expand Down
38 changes: 37 additions & 1 deletion homestar-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ autotests = false
path = "src/lib.rs"
bench = false
doctest = true
crate-type = ["cdylib", "rlib"]

[[bin]]
name = "homestar"
Expand Down Expand Up @@ -204,3 +203,40 @@ websocket-server = ["dep:axum"]
all-features = true
# defines the configuration attribute `docsrs`
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.deb]
maintainer = "James Walker <[email protected]>"
license-file = ["LICENSE", "0"]
extended-description-file = "README.md"
section = "network"
priority = "optional"
assets = [
[
"../target/x86_64-unknown-linux-musl/release/homestar",
"usr/bin/",
"755",
],
[
"../CHANGELOG.md",
"usr/share/doc/homestar/",
"644",
],
[
"../LICENSE",
"usr/share/doc/homestar/",
"644",
],
[
"../README.md",
"usr/share/doc/homestar/",
"644",
],
]

[package.metadata.generate-rpm]
assets = [
{ source = "../target/x86_64-unknown-linux-musl/release/homestar", dest = "/usr/bin/homestar", mode = "755" },
{ source = "../CHANGELOG.md", dest = "/usr/share/doc/homestar/CHANGELOG.md", mode = "644", doc = true },
{ source = "../LICENSE", dest = "/usr/share/doc/homestar/LICENSE.md", mode = "644", doc = true },
{ source = "../README.md", dest = "/usr/share/doc/homestar/README.md", mode = "644", doc = true },
]
2 changes: 1 addition & 1 deletion homestar-runtime/src/network/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub(crate) fn init(
swarm.listen_on(settings.listen_address.to_string().parse()?)?;

// add external addresses from settings
if settings.announce_addresses.is_empty() {
if !settings.announce_addresses.is_empty() {
for addr in settings.announce_addresses.iter() {
swarm.add_external_address(addr.clone());
}
Expand Down
Loading
Loading