Skip to content

mirror

mirror #2189

Workflow file for this run

name: CI
on:
push:
branches: [ master ]
tags: "[0-9]+.[0-9]+.[0-9]+"
pull_request:
branches: [ master ]
workflow_dispatch:
env:
DOTNET_VERSION: '8'
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Set Environment Variables
run: |
echo "VERSION=$(git describe --tags --abbrev=0).$([[ $GITHUB_REF = refs/tags/* ]] && echo 0 || echo 65534)+$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Web
run: ./bin/build --web-only
- name: Dotnet
run: ./bin/build --dotnet-only --version ${{ env.VERSION }}
- name: Upload Static Web Content
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v4
with:
name: web-${{ env.VERSION }}
path: src/web/build
publish:
name: Publish
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
runtime:
- "win-x64"
- "win-arm64"
- "linux-x64"
- "linux-arm"
- "linux-arm64"
- "linux-musl-x64"
- "linux-musl-arm"
- "linux-musl-arm64"
- "osx-x64"
- "osx-arm64"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Set Environment Variables
run: |
echo "VERSION=$(git describe --tags --abbrev=0).$([[ $GITHUB_REF = refs/tags/* ]] && echo 0 || echo 65534)+$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Download Static Web Content
uses: actions/download-artifact@v4
with:
name: web-${{ env.VERSION }}
path: src/slskd/wwwroot
- name: Build ${{ matrix.runtime }}
run: bin/publish --no-prebuild --runtime ${{ matrix.runtime }} --version ${{ env.VERSION }}
- name: Upload Binaries
uses: actions/upload-artifact@v4
with:
name: slskd-${{ env.VERSION }}-${{ matrix.runtime }}
path: dist/${{ matrix.runtime }}
docker:
name: Build Docker Image
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# docker tags aren't compatible with semver, therefore + can't be used to delimit the version and SHA
# https://github.com/opencontainers/distribution-spec/issues/154
# CONTAINER_VERSION is used in Docker tags and must use a hyphen (-) delimiter between the tag and SHA
# APP_VERSION is passed as a Docker build arg and used to publish the app and must use a plus (+) delimiter between the tag and SHA
- name: Set Environment Variables
run: |
echo "TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
echo "CONTAINER_VERSION=$(git describe --tags --abbrev=0).$([[ $GITHUB_REF = refs/tags/* ]] && echo 0 || echo 65534)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "APP_VERSION=$(git describe --tags --abbrev=0).$([[ $GITHUB_REF = refs/tags/* ]] && echo 0 || echo 65534)+$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "REVISION=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "BUILD_DATE=$(date --iso-8601=s)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_PAT }}
- name: Build and push Canary
if: "!startsWith(github.ref, 'refs/tags/')"
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
build-args: |
TAG=${{ env.TAG }}
VERSION=${{ env.APP_VERSION }}
REVISION=${{ env.REVISION }}
BUILD_DATE=${{ env.BUILD_DATE }}
tags: |
slskd/slskd:${{ env.CONTAINER_VERSION }}
slskd/slskd:canary
ghcr.io/slskd/slskd:${{ env.CONTAINER_VERSION }}
ghcr.io/slskd/slskd:canary
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push Release
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
build-args: |
VERSION=${{ env.APP_VERSION }}
tags: |
slskd/slskd:${{ env.CONTAINER_VERSION }}
slskd/slskd:${{ env.TAG }}
slskd/slskd:canary
slskd/slskd:latest
ghcr.io/slskd/slskd:${{ env.CONTAINER_VERSION }}
ghcr.io/slskd/slskd:${{ env.TAG }}
ghcr.io/slskd/slskd:canary
ghcr.io/slskd/slskd:latest
cache-from: type=gha
cache-to: type=gha,mode=max
release:
name: Create Release
runs-on: ubuntu-latest
needs: [publish, docker]
if: startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
runtime:
- "win-x64"
- "win-arm64"
- "linux-x64"
- "linux-arm"
- "linux-arm64"
- "linux-musl-x64"
- "linux-musl-arm"
- "linux-musl-arm64"
- "osx-x64"
- "osx-arm64"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set Environment Variables
run: |
echo "TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
echo "VERSION=$(git describe --tags --abbrev=0).$([[ $GITHUB_REF = refs/tags/* ]] && echo 0 || echo 65534)+$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Download ${{ matrix.runtime }} Binaries
uses: actions/download-artifact@v4
with:
name: slskd-${{ env.VERSION }}-${{ matrix.runtime }}
path: dist/${{ matrix.runtime }}
- name: Zip ${{ matrix.runtime }} Binaries
run: |
cd dist/${{ matrix.runtime }}
if [ -f "slskd" ]; then
chmod +x slskd
fi
zip -r ../../slskd-${{ env.TAG }}-${{ matrix.runtime }}.zip .
- name: Create Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
slskd-${{ env.TAG }}-${{ matrix.runtime }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}