navidrome/.github/workflows/pipeline.yml
Rob Emery 768160b05e
feat: Windows MSI installer and service support (#3125)
* First version/rough layout of the required wix to build an MSI that embeds everything

* Don't need revision number

* produced exe from existing build process is navidrome not Navidrome

* Adding Kardianos wrapper around Cobra so the callbacks are handled
automatically (this is basically only for windows)

* Adding pointless check to shut up lint for now

* make format

* Revert disabling npm tidy

* Using Kardianos always will result in the application hanging so it
needs only be wrapped to handle the callbacks if it's being used in
the service context, otherwise use cobra directly

* Copying in service installation etc from https://github.com/navidrome/navidrome/pull/2295

* Under Linux this installs a user service (I don't think this is
correct, but lets get this working first). User units/services
cannot depends on system units, so previously this bombed out
with Exit Code 5.

* Under Windows we can install both the x86 and x64 builds, they
will install to different folders, but previously they would
overwrite the service as they were both called Navidrome. Now,
it will install 2 services. This will still be weird/broken as
they will attempt to listen on the same port, however uninstalling
the "wrong" arch will not cause the "right" one to be partially
uninstalled anymore

* Reverting changes to the context as they don't really seem necessary anyway

* Need to consistently name the service

* Fixing broken context

* The included files should be removed when the app is uninstalled

* Reverting back to the original context here, I don't think
it makes any difference to running under kardianos

* Let's see what we have immediately available

* OK, the build takes ages so let's just try and do the whole thing in one go, maybe we'll get lucky

* Need -r on directory copy, plus we'll probably need to install wixl

* No sudo cmd, so I assume this runs as root

* WORKSPACE!

* Moving the version to be a single variable, we'll probably be able to pull it from the github tag or whatever

* Might as well put the msi in the right folder, it's tidier

* Writing the version number into the msi, from the output of goreleaser

* Using jq to parse the goreleaser metadata, so need to install it

* MSI only supports numerical version numbers, so I'll make the "snapshot" version .1 minor patch greater

* -r or --raw (on newer versions) means we don't get the "" around the value

* Running as a user service I think makes limited sense for this

* Will now ask for configuration settings during install.

MSI/WiX only supports writing out INI files, Toml is almost
INI compatable, except that the INI needs to write out a section
first, so we need to have a script to strip that off.

We are forced to display a License.rtf file by the UI so I think
the build process should probably rename the default licence file
and that will suffice.

Uninstalling works cleanly, howvever upgrades seem to leave the old
version installed in "programs and features" currently.

Adding the UI has introduced a requirement for WiX 0.103

* Updating the build to include --ext ui for the new config ui

* Configuration dialog should not display for upgrades as the config file
is already written

* Making description consistent with the systemd service and making
the build process produce the required License.rtf

* Fixing " non-constant format string in call to fmt.Errorf (govet)"

* Its a string, not an int; read better.

* Wixl 103 is required for --ext ui, so we need 24.04

* OK this is still installing Wix 0.101, maybe it all needs to be 24.04?

* Switching the builds back to ubuntu-latest (22.04 at current)
as it runs on a custom container, it's actually debian anyway
Moving msi build into its own job so it can run on 24.04 so
we have access to wixl 0.103 for --ext ui support

* Forcing build

* Whitespace fix

* Adding sudo I guess

* Gotta checkout as well

* Adding debugging for when there's soemthing wrong with the paths

* Adding more ls to see if the output has worked

* The msi's are in subdirs

* Actually they're in the ./wix directory

* Still can't find these msi's?

* I think that was being treated literally previously

* No idea why this isn't working, give it a relative path instead?

* Making explicit on the dialogue that the configuration file will be
where the installation dir is

* The lint keeps failing and it's just getting in the way so I'll
turn this off for now and we'll edit out this commit from the merge

* Cutting more out of the build to get more stuff out of the way

* Need to increase the width to fit the text in

* Calling everything License.rtf, presumably one of them is correct

* I am pretty sure the License.rtf loading is broken under Wixl; so
let's just bypass the EULA from the UI which is a nicer experience
for the users anyway

* This needs to be after WelcomeDlg now the Eula isn't displayed

* You're supposed to be able to use <WixVariable> to override the
location that the bmp's are loaded from, I can't get this to work
under wixl so I'm guessing given that the ui extension is new, it
hasn't been implemented with that in mind. So we'll hack it by
overwriting the files installed with the package.

* We should make this less brittle so when wixl is updated it still works

* Re-enabling the lint and tests etc

* Improving the scaling quality and removing borders from images to
tidy them up a tad

* Pretty sure this isn't necessary as MY_PROPERTY will always be false

* Without publishing this event, we can't continue to the next dialogue
however I think we should be able to get away without the property

* Refactoring out the duplication so we only have one service
defined and we can run that either way

* Pushing the Interactive check into the root commmand? Feels like it
is probably getting closer to the right place at least

* go tidy

* OK this didn't work under windows, I'm guessing it's because
it's lacking all the metadata about the service it needs to
report back to Windows on.

* We need to run service execute now so that the windows
service will behave (hopefully)!

* Lint

* go tidy

* Renaming service to "navidrome" rather than "Navidrome" as this
is the filename that systemd writes and it's unusual to have
capital letters in service names under Linux.
Switching to use service execute for Linux to mirror Windows

* Need to provide the arguments to append

* Without passing the context around, the DB isn't closed gracefully
so we end up with with .db-shm and .db-wal files for recovery

* We should log fatal rather than outputting directly to stdout

* go tidy

* refactor: small nitpicks

* fix: terminate service gracefully

---------

Co-authored-by: Deluan Quintão <deluan@navidrome.org>
2024-10-01 19:40:53 -04:00

267 lines
7.9 KiB
YAML

name: "Pipeline: Test, Lint, Build"
on:
push:
branches:
- master
tags:
- "v*"
pull_request:
branches:
- master
jobs:
go-lint:
name: Lint Go code
runs-on: ubuntu-latest
container: deluan/ci-goreleaser:1.23.0-1
steps:
- uses: actions/checkout@v4
- name: Config workspace folder as trusted
run: git config --global --add safe.directory $GITHUB_WORKSPACE; git describe --dirty --always --tags
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
problem-matchers: true
args: --timeout 2m
- name: Install goimports
run: go install golang.org/x/tools/cmd/goimports@latest
- run: goimports -w `find . -name '*.go' | grep -v '_gen.go$'`
- run: go mod tidy
- name: Verify no changes from goimports and go mod tidy
run: |
git status --porcelain
if [ -n "$(git status --porcelain)" ]; then
echo 'To fix this check, run "make format" and commit the changes'
exit 1
fi
go:
name: Test Go code
runs-on: ubuntu-latest
container: deluan/ci-goreleaser:1.23.0-1
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Config workspace folder as trusted
run: git config --global --add safe.directory $GITHUB_WORKSPACE; git describe --dirty --always --tags
- name: Download dependencies
if: steps.cache-go.outputs.cache-hit != 'true'
continue-on-error: ${{contains(matrix.go_version, 'beta') || contains(matrix.go_version, 'rc')}}
run: go mod download
- name: Test
continue-on-error: ${{contains(matrix.go_version, 'beta') || contains(matrix.go_version, 'rc')}}
run: go test -shuffle=on -race -cover ./... -v
js:
name: Build JS bundle
runs-on: ubuntu-latest
env:
NODE_OPTIONS: "--max_old_space_size=4096"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: npm install dependencies
run: |
cd ui
npm ci
- name: npm lint
run: |
cd ui
npm run check-formatting && npm run lint
- name: npm test
run: |
cd ui
npm test
- name: npm build
run: |
cd ui
npm run build
- uses: actions/upload-artifact@v4
with:
name: js-bundle
path: ui/build
retention-days: 7
i18n-lint:
name: Lint i18n files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
set -e
for file in resources/i18n/*.json; do
echo "Validating $file"
if ! jq empty "$file" 2>error.log; then
error_message=$(cat error.log)
line_number=$(echo "$error_message" | grep -oP 'line \K[0-9]+')
echo "::error file=$file,line=$line_number::$error_message"
exit 1
fi
done
binaries:
name: Build binaries
needs: [js, go, go-lint, i18n-lint]
runs-on: ubuntu-latest
container: deluan/ci-goreleaser:1.23.0-1
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Config workspace folder as trusted
run: git config --global --add safe.directory $GITHUB_WORKSPACE; git describe --dirty --always --tags
- uses: actions/download-artifact@v4
with:
name: js-bundle
path: ui/build
- name: Run GoReleaser - SNAPSHOT
if: startsWith(github.ref, 'refs/tags/') != true
run: goreleaser release --clean --skip=publish --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run GoReleaser - RELEASE
if: startsWith(github.ref, 'refs/tags/')
run: goreleaser release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/upload-artifact@v4
with:
name: binaries
path: |
dist
!dist/*.tar.gz
!dist/*.zip
retention-days: 7
msi:
name: Build and publish MSI files
needs: [binaries]
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: binaries
path: dist
- name: Build MSI
run: |
sudo apt-get install -y wixl jq
NAVIDROME_BUILD_VERSION=$(jq -r '.version' < $GITHUB_WORKSPACE/dist/metadata.json | sed -e 's/^v//' -e 's/-SNAPSHOT/.1/' )
mkdir -p $GITHUB_WORKSPACE/wix/386
cp $GITHUB_WORKSPACE/LICENSE $GITHUB_WORKSPACE/wix/386
cp $GITHUB_WORKSPACE/README.md $GITHUB_WORKSPACE/wix/386
cp -r $GITHUB_WORKSPACE/wix/386 $GITHUB_WORKSPACE/wix/amd64
cp $GITHUB_WORKSPACE/dist/navidrome_windows_386_windows_386/navidrome.exe $GITHUB_WORKSPACE/wix/386
cp $GITHUB_WORKSPACE/dist/navidrome_windows_amd64_windows_amd64_v1/navidrome.exe $GITHUB_WORKSPACE/wix/amd64
# workaround for wixl WixVariable not working to override bmp locations
sudo cp $GITHUB_WORKSPACE/wix/bmp/banner.bmp /usr/share/wixl-*/ext/ui/bitmaps/bannrbmp.bmp
sudo cp $GITHUB_WORKSPACE/wix/bmp/dialogue.bmp /usr/share/wixl-*/ext/ui/bitmaps/dlgbmp.bmp
cd $GITHUB_WORKSPACE/wix/386
wixl ../navidrome.wxs -D Version=$NAVIDROME_BUILD_VERSION -D Platform=x86 --arch x86 --ext ui --output ../navidrome_386.msi
cd $GITHUB_WORKSPACE/wix/amd64
wixl ../navidrome.wxs -D Version=$NAVIDROME_BUILD_VERSION -D Platform=x64 --arch x64 --ext ui --output ../navidrome_amd64.msi
ls -la $GITHUB_WORKSPACE/wix/*.msi
- uses: actions/upload-artifact@v4
with:
name: installers
path: wix/*.msi
retention-days: 7
docker:
name: Build and publish Docker images
needs: [binaries]
runs-on: ubuntu-latest
env:
DOCKER_IMAGE: ${{secrets.DOCKER_IMAGE}}
steps:
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v3
if: env.DOCKER_IMAGE != ''
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
if: env.DOCKER_IMAGE != ''
- uses: actions/checkout@v4
if: env.DOCKER_IMAGE != ''
- uses: actions/download-artifact@v4
if: env.DOCKER_IMAGE != ''
with:
name: binaries
path: dist
- name: Login to Docker Hub
if: env.DOCKER_IMAGE != ''
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to GitHub Container Registry
if: env.DOCKER_IMAGE != ''
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
if: env.DOCKER_IMAGE != ''
id: meta
uses: docker/metadata-action@v5
with:
labels: |
maintainer=deluan
images: |
name=${{secrets.DOCKER_IMAGE}}
name=ghcr.io/${{ github.repository }}
tags: |
type=ref,event=pr
type=semver,pattern={{version}}
type=raw,value=develop,enable={{is_default_branch}}
- name: Build and Push
if: env.DOCKER_IMAGE != ''
uses: docker/build-push-action@v5
with:
context: .
file: .github/workflows/pipeline.dockerfile
platforms: linux/amd64,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}