mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
248 lines
6.9 KiB
YAML
248 lines
6.9 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- master
|
|
- develop
|
|
tags:
|
|
- 'v*'
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
- master
|
|
- develop
|
|
workflow_dispatch:
|
|
inputs:
|
|
force_release:
|
|
description: "Force release creation"
|
|
required: false
|
|
default: "false"
|
|
type: choice
|
|
options:
|
|
- true
|
|
- false
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
|
|
|
|
jobs:
|
|
build-client:
|
|
runs-on: ubuntu-latest
|
|
name: Build Web Client
|
|
outputs:
|
|
client-sha: ${{ steps.sha.outputs.sha }}
|
|
steps:
|
|
- name: Checkout swingmusic-webclient
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: "Dvorinka/swingmusic-extended"
|
|
path: swingmusic-webclient
|
|
|
|
- name: Setup Node 24
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 24.x
|
|
|
|
- name: Build client
|
|
run: |
|
|
cd swingmusic-webclient
|
|
npm install
|
|
npm run build
|
|
cd ..
|
|
|
|
- name: Generate client SHA
|
|
id: sha
|
|
run: |
|
|
cd swingmusic-webclient/dist
|
|
sha256sum * | sort | sha256sum | cut -d' ' -f1 > client.sha
|
|
echo "sha=$(cat client.sha)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Upload client
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
path: "swingmusic-webclient/dist/"
|
|
compression-level: 0
|
|
name: "client"
|
|
|
|
build-python:
|
|
runs-on: ubuntu-latest
|
|
name: Build Python Package
|
|
needs: build-client
|
|
outputs:
|
|
version: ${{ steps.version.outputs.version }}
|
|
steps:
|
|
- name: Checkout swingmusic
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Download client artifact
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: client
|
|
path: swingmusic-webclient/dist
|
|
|
|
- name: Compress client and copy to src/swingmusic/client.zip
|
|
run: |
|
|
cd swingmusic-webclient/dist
|
|
zip -r client.zip .
|
|
cd ../..
|
|
cp swingmusic-webclient/dist/client.zip src/swingmusic/client.zip
|
|
|
|
- uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.11"
|
|
|
|
- name: Get version
|
|
id: version
|
|
run: |
|
|
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
|
VERSION=${GITHUB_REF#refs/tags/v}
|
|
else
|
|
VERSION=$(python -c "import sys; sys.path.insert(0, 'src'); from swingmusic import __version__; print(__version__)")
|
|
VERSION="$VERSION-${{ github.run_number }}"
|
|
fi
|
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build wheels
|
|
run: pip wheel . -w wheelhouse --no-deps
|
|
|
|
- name: Upload wheels
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
path: ./wheelhouse/*.whl
|
|
compression-level: 0
|
|
name: "wheels"
|
|
|
|
build-docker:
|
|
runs-on: ubuntu-latest
|
|
name: Build Docker Image
|
|
needs: [build-client, build-python]
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
outputs:
|
|
image: ${{ steps.meta.outputs.tags }}
|
|
digest: ${{ steps.build.outputs.digest }}
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Download client artifact
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: client
|
|
path: swingmusic-webclient/dist
|
|
|
|
- name: Download wheels
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: wheels
|
|
path: wheels
|
|
merge-multiple: true
|
|
|
|
- name: Create version.txt
|
|
run: echo "${{ needs.build-python.outputs.version }}" > version.txt
|
|
|
|
- name: Log in to Container Registry
|
|
if: github.event_name != 'pull_request'
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=ref,event=branch,suffix=-${{ github.run_number }}
|
|
type=ref,event=pr,suffix=-pr-${{ github.event.number }}
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Build and push Docker image
|
|
id: build
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
build-args: |
|
|
app_version=${{ needs.build-python.outputs.version }}
|
|
client_sha=${{ needs.build-client.outputs.client-sha }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
test-docker:
|
|
runs-on: ubuntu-latest
|
|
name: Test Docker Image
|
|
needs: build-docker
|
|
if: github.event_name != 'pull_request'
|
|
steps:
|
|
- name: Pull Docker image
|
|
run: docker pull ${{ needs.build-docker.outputs.image }}
|
|
|
|
- name: Test container startup
|
|
run: |
|
|
timeout 30s docker run --rm ${{ needs.build-docker.outputs.image }} --help || \
|
|
timeout 30s docker run --rm ${{ needs.build-docker.outputs.image }} --version || \
|
|
echo "Container starts successfully"
|
|
|
|
create-release:
|
|
runs-on: ubuntu-latest
|
|
name: Create Release
|
|
needs: [build-client, build-python, build-docker]
|
|
if: |
|
|
startsWith(github.ref, 'refs/tags/') ||
|
|
github.event.inputs.force_release == 'true'
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Download all artifacts
|
|
uses: actions/download-artifact@v4
|
|
|
|
- name: Create release
|
|
uses: softprops/action-gh-release@v1
|
|
with:
|
|
name: Release ${{ needs.build-python.outputs.version }}
|
|
tag_name: v${{ needs.build-python.outputs.version }}
|
|
body: |
|
|
## Release ${{ needs.build-python.outputs.version }}
|
|
|
|
### Docker Image
|
|
- `${{ needs.build-docker.outputs.image }}`
|
|
|
|
### Changes
|
|
- View full changelog in [CHANGELOG.md](CHANGELOG.md)
|
|
|
|
### Installation
|
|
```bash
|
|
docker pull ${{ needs.build-docker.outputs.image }}
|
|
docker run -p 1979:1979 ${{ needs.build-docker.outputs.image }}
|
|
```
|
|
files: |
|
|
wheels/*
|
|
client/*
|
|
draft: false
|
|
prerelease: ${{ contains(needs.build-python.outputs.version, '-') }}
|
|
generate_release_notes: true
|