Skip to content
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
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[registries.crates-io]
protocol = "sparse"
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Main

on:
pull_request:
branches: ["master"]

env:
CARGO_TERM_COLOR: always

jobs:
tests:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Update Toolchain
run: rustup update nightly && rustup default nightly # Until edition 2024 becomes stable
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo --version && cargo build --locked
142 changes: 142 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: Release

on:
push:
tags:
- 'v*'

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

jobs:
build-binaries:
name: Build Release Binaries
runs-on: ubuntu-latest
strategy:
matrix:
include:
- TARGET: x86_64-unknown-linux-gnu
- TARGET: x86_64-unknown-linux-musl
- TARGET: aarch64-unknown-linux-gnu
- TARGET: aarch64-unknown-linux-musl
- TARGET: armv7-unknown-linux-gnueabihf
steps:
- uses: actions/checkout@v4

- name: Get version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

- name: Update Toolchain
run: rustup update nightly && rustup default nightly # Until edition 2024 becomes stable

- name: Install Dependencies
run: |
sudo apt-get install -yqq crossbuild-essential-arm64 crossbuild-essential-armhf musl-tools

cat > ~/.cargo/config.toml <<EOF
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-gnu-gcc"
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
[target.armv7-unknown-linux-musleabihf]
linker = "arm-linux-gnueabihf-gcc"
EOF

- uses: Swatinem/rust-cache@v2

- name: Install cargo-edit
run: cargo install -f --no-default-features --features "set-version" cargo-edit

- name: Set version
run: cargo set-version ${{ steps.get_version.outputs.VERSION }}

- name: Build binary
uses: actions-rs/cargo@v1
with:
command: build
args: --release --locked --target ${{ matrix.target }}

- name: Package
run: |
tagName=${GITHUB_REF#refs/tags/v}
executableName=gjallarbot
mkdir -p dist
mv target/$TARGET/release/$executableName dist/${executableName}-v${tagName}-${TARGET}
- uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.TARGET }}
path: dist/
if-no-files-found: error

build-containers:
name: Build and Push Container Images
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

- name: Get version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

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

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker images
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
build-args: |
VERSION=${{ steps.get_version.outputs.VERSION }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }}

create-release:
name: Create Release
needs: [build-binaries, build-containers]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Get version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

- name: Download Release Binaries
uses: actions/download-artifact@v4
with:
pattern: binary-*
path: ./dist/
merge-multiple: true

- name: Release
uses: softprops/action-gh-release@v2
with:
body: |
Release ${{ steps.get_version.outputs.VERSION }}

Docker images are available at:
```bash
docker pull ghcr.io/${{ github.repository }}:${{ steps.get_version.outputs.VERSION }}
```
generate_release_notes: true
files: ./dist/*
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

Expand Down
Loading