Skip to content

Merge pull request #77 from SierraSoftworks/dependabot/github_actions… #246

Merge pull request #77 from SierraSoftworks/dependabot/github_actions…

Merge pull request #77 from SierraSoftworks/dependabot/github_actions… #246

Workflow file for this run

name: Rust
on:
push: {}
release:
types: [published]
env:
VERSION: "0.0.0-dev"
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
version:
name: Start Release
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Generate Package Version (Release Tag)
shell: pwsh
if: github.event_name == 'release'
run: Add-Content -Path $env:GITHUB_ENV -Value "VERSION=$('${{ github.event.release.tag_name }}'.substring(1))"
- name: Set Package Version
run: sed -i "s/^version\s*=\s*\".*\"/version = \"$VERSION\"/g" Cargo.toml
- name: Stash Versioned Cargo.toml
uses: actions/upload-artifact@v4
with:
name: cargofile
path: Cargo.toml
test:
name: Test
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: llvm-tools-preview
- name: cargo install grcov
uses: SierraSoftworks/setup-grcov@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run tests
run: cargo test --no-fail-fast
env:
RUSTFLAGS: -Cinstrument-coverage
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: grcov
run: grcov . --binary-path target/debug/deps/ -s . -t lcov --ignore-not-existing --ignore '../**' --ignore '/*' --ignore 'C:/' -o ./lcov.info
- name: codecov upload
uses: codecov/[email protected]
with:
files: ./lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
build:
name: ${{ matrix.os }}-${{ matrix.arch }}-release
runs-on: ${{ matrix.run_on }}
needs:
- version
strategy:
matrix:
include:
# Windows builds
- arch: amd64
os: windows
run_on: windows-latest
target: x86_64-pc-windows-msvc
extension: .exe
builder: cargo
# Linux builds
- arch: amd64
run_on: ubuntu-latest
os: linux
target: x86_64-unknown-linux-gnu
test: true
builder: cargo
- arch: "arm64"
os: linux
run_on: ubuntu-latest
target: aarch64-unknown-linux-gnu
builder: cross
# Apple MacOS builds
- arch: amd64
run_on: macos-latest
os: darwin
target: x86_64-apple-darwin
builder: cargo
- arch: arm64
run_on: macos-latest
os: darwin
target: aarch64-apple-darwin
builder: cargo
steps:
- name: Get Rust Stable
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
target: ${{ matrix.target }}
components: llvm-tools-preview
- name: Setup Cache
uses: Swatinem/rust-cache@v2
- name: Check out code
uses: actions/checkout@v4
- name: Fetch Versioned Cargo.toml
uses: actions/download-artifact@v4
with:
name: cargofile
- name: Install Cross
if: matrix.builder == 'cross'
shell: bash
run: |
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
cargo binstall --no-confirm cross
- name: cargo build
run: ${{ matrix.builder }} build --release --target ${{ matrix.target }}
- name: Upload GitHub Release Artifacts
uses: SierraSoftworks/[email protected]
if: github.event_name == 'release'
with:
files: "target/${{ matrix.target }}/release/github-backup${{ matrix.extension }} | github-backup-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.extension }}"
token: ${{ secrets.GITHUB_TOKEN }}
overwrite: "true"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: github-backup-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.extension }}
path: target/${{ matrix.target }}/release/github-backup${{ matrix.extension }}
docker-build:
name: Docker Build
runs-on: ubuntu-latest
needs:
- build
if: github.event_name == 'release'
permissions:
contents: read
packages: write
id-token: write
strategy:
fail-fast: false
matrix:
platform: [linux/amd64, linux/arm64]
steps:
- name: set environment variables
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
image="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
image="$(echo $image | tr '[:upper:]' '[:lower:]')"
echo "FULL_IMAGE_NAME=${image}" >> $GITHUB_ENV
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.FULL_IMAGE_NAME }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Checkout code
uses: actions/checkout@v4
- name: Pull in platform artifact
uses: actions/download-artifact@v4
with:
name: github-backup-${{ env.PLATFORM_PAIR }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true,annotation-index.org.opencontainers.image.description=Backup your GitHub repositories and releases automatically
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: image-digest-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
docker-publish:
name: Docker Publish
runs-on: ubuntu-latest
needs:
- docker-build
if: github.event_name == 'release'
permissions:
contents: read
packages: write
id-token: write
steps:
- name: set environment variables
run: |
image="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
image="$(echo $image | tr '[:upper:]' '[:lower:]')"
echo "FULL_IMAGE_NAME=${image}" >> $GITHUB_ENV
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: image-digest-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.FULL_IMAGE_NAME }}
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- 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 '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}