Skip to content

Commit

Permalink
⚡️ Improve CI
Browse files Browse the repository at this point in the history
  • Loading branch information
gorillamoe committed May 11, 2024
1 parent b45651e commit 374791b
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 54 deletions.
103 changes: 62 additions & 41 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,55 +1,76 @@
name: Build and Release
name: Release

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
# build:
# name: Default Build and Release
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# with:
# fetch-depth: 0
# - name: Install wine
# run: |
# sudo dpkg --add-architecture i386
# sudo apt update
# sudo apt install -y wine64 wine32
# - name: Set up env
# run: |
# VERSION=${GITHUB_REF_NAME#v}
# echo "VERSION=$VERSION" >> $GITHUB_ENV
# - name: Set up Node
# uses: actions/setup-node@v3
# with:
# node-version: 20
# - name: Install node dependencies
# run: npm ci
# - name: Build Linux
# run: make linux
# - name: Build Windows
# run: make windows
# - name: Archive
# run: make archives
# - name: Default Release
# run: make default-release VERSION=$VERSION
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
buildpatch:
# needs: build
name: Build MacOS and Patch Release
build-linux:
name: Build Linux
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up env
run: |
VERSION=${GITHUB_REF_NAME#v}
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 20
- name: Install node dependencies
run: npm ci
- name: Build Linux
run: make linux
- name: Archive
run: make archives PLATFORM=linux VERSION=$VERSION
- name: Linux Release
run: make linux-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-windows:
name: Build Windows
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install wine
run: |
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install -y wine64 wine32
- name: Set up env
run: |
VERSION=${GITHUB_REF_NAME#v}
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 20
- name: Install node dependencies
run: npm ci
- name: Build Windows
run: make windows
- name: Windows Release
run: make windows-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-macos:
name: Build MacOS
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# https://github.com/electron/forge/issues/2807
- name: Install python3 setuptools
run: brew install python-setuptools tree
- name: Install python3-setuptools and bash
run: brew install python-setuptools bash
- name: Set up env
run: |
VERSION=${GITHUB_REF_NAME#v}
Expand All @@ -62,7 +83,7 @@ jobs:
run: npm ci
- name: Build MacOS
run: make macos
- name: Patch Release (MacOS)
run: make macos-release VERSION=$VERSION
- name: MacOS Release
run: make macos-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22 changes: 14 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
BIN_NAME = timetrack.desktop

macos:
npm run make -- --arch=x64 --platform=darwin
PLATFORM=macos ./scripts/build.sh

linux:
npm run make -- --arch=x64 --platform=linux
PLATFORM=linux ./scripts/build.sh

windows:
npm run make -- --arch=x64 --platform=win32
PLATFORM=windows ./scripts/build.sh

archives:
cd out/ && tar -czvf $(BIN_NAME)_$(VERSION)_linux-x64.tar.gz $(BIN_NAME)-linux-x64
CREATE_ARCHIVES=1 PLATFORM=linux ./scripts/release.sh

linux-release:
REPLACE=1 PLATFORM=linux ./scripts/release.sh

windows-release:
REPLACE=1 PLATFORM=windows ./scripts/release.sh

default-release:
gh release create --generate-notes v$(VERSION) out/make/deb/x64/$(BIN_NAME)_$(VERSION)_amd64.deb out/make/rpm/x64/$(BIN_NAME)-$(VERSION)-1.x86_64.rpm "out/make/squirrel.windows/x64/timetrack.desktop-$(VERSION) Setup.exe" out/make/squirrel.windows/x64/timetrack.desktop-$(VERSION)-full.nupkg
macos-release:
tree out/
# gh release edit v$(VERSION)
REPLACE=1 PLATFORM=macos ./scripts/release.sh

run:
npm run start
9 changes: 5 additions & 4 deletions forge.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path');
const { FusesPlugin } = require('@electron-forge/plugin-fuses');
const { FuseV1Options, FuseVersion } = require('@electron/fuses');

Expand All @@ -12,14 +13,14 @@ module.exports = {
name: '@electron-forge/maker-squirrel',
config: {
iconUrl: 'https://raw.githubusercontent.com/mistweaverco/timetrack.desktop/main/src/assets/icon/icon.ico',
setupIcon: 'src/assets/icon/icon.ico'
setupIcon: path.resolve(__dirname, 'src/assets/icon/icon.ico'),
},
},
{
name: '@electron-forge/maker-dmg',
config: {
options: {
icon: 'src/assets/icon/icon.icns',
icon: path.resolve(__dirname, 'src/assets/icon/icon.icns'),
format: 'ULFO'
}
},
Expand All @@ -28,15 +29,15 @@ module.exports = {
name: '@electron-forge/maker-deb',
config: {
options: {
icon: 'src/assets/icon/icon.png'
icon: path.resolve(__dirname, 'src/assets/icon/icon.png')
}
},
},
{
name: '@electron-forge/maker-rpm',
config: {
options: {
icon: 'src/assets/icon/icon.png'
icon: path.resolve(__dirname, 'src/assets/icon/icon.png')
}
},
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "timetrack.desktop",
"version": "1.0.1",
"version": "1.0.3",
"description": "Simple desktop application to track your time spent on different projects.",
"main": "app/process.js",
"scripts": {
Expand Down
35 changes: 35 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

if [ -z "$VERSION" ]; then echo "Error: VERSION is not set"; exit 1; fi
if [ -z "$PLATFORM" ]; then echo "Error: PLATFORM is not set"; exit 1; fi

BUILDOS=""

update_package_json_version() {
local tmp
tmp=$(mktemp)
jq --arg v "$VERSION" '.version = $v' package.json > "$tmp" && mv "$tmp" package.json
}

set_buildos_based_on_platform() {
case $PLATFORM in
linux)
BUILDOS="linux"
;;
windows)
BUILDOS="win32"
;;
macos)
BUILDOS="darwin"
;;
*)
echo "Error: PLATFORM $PLATFORM is not supported"
exit 1
;;
esac
}

set_buildos_based_on_platform
update_package_json_version

npm run make -- --arch=x64 --platform=$BUILDOS
114 changes: 114 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env bash

if [ -z "$VERSION" ]; then echo "Error: VERSION is not set"; exit 1; fi
if [ -z "$PLATFORM" ]; then echo "Error: PLATFORM is not set"; exit 1; fi

BIN_NAME="timetrack.desktop"
RELEASE_ACTION="create"
GH_TAG="v$VERSION"
FILES=()

LINUX_FILES=(
"out/make/deb/x64/${BIN_NAME}_${VERSION}_amd64.deb"
"out/make/rpm/x64/${BIN_NAME}-${VERSION}-1.x86_64.rpm"
)

WINDOWS_FILES=(
"out/make/squirrel.windows/x64/${BIN_NAME}-${VERSION} Setup.exe"
"out/make/squirrel.windows/x64/${BIN_NAME}-${VERSION}-full.nupkg"
)

MACOS_FILES=(
"out/make/$BIN_NAME-$VERSION-x64.dmg"
)


set_release_action() {
if gh release view "$GH_TAG" --json id --jq .id > /dev/null 2>&1; then
echo "Release $GH_TAG already exists, updating it"
RELEASE_ACTION="edit"
else
echo "Release $GH_TAG does not exist, creating it"
RELEASE_ACTION="create"
fi
}

check_files_exist() {
files=()
for file in "${FILES[@]}"; do
if [ ! -f "$file" ]; then
files+=("$file")
fi
done
if [ ${#files[@]} -gt 0 ]; then
echo "Error: the following files do not exist:"
for file in "${files[@]}"; do
printf " - %s\n" "$file"
done
exit 1
fi
}

set_files_based_on_platform() {
case $PLATFORM in
linux)
FILES=("${LINUX_FILES[@]}")
;;
windows)
FILES=("${WINDOWS_FILES[@]}")
;;
macos)
FILES=("${MACOS_FILES[@]}")
;;
*)
echo "Error: PLATFORM $PLATFORM is not supported"
exit 1
;;
esac
}

print_files() {
echo "Files to upload:"
for file in "${FILES[@]}"; do
printf " - %s\n" "$file"
done
}

do_gh_release() {
if [ "$RELEASE_ACTION" == "edit" ]; then
if [ -z "$REPLACE" ]; then
echo "Trying to upload files to existing release $GH_TAG"
print_files
gh release upload "$GH_TAG" "${FILES[@]}"
else
echo "Overwriting existing release $GH_TAG"
print_files
gh release upload --clobber "$GH_TAG" "${FILES[@]}"
fi
else
echo "Creating new release $GH_TAG"
print_files
gh release create --generate-notes "$GH_TAG" "${FILES[@]}"
fi
}

create_archives() {
cd out/ && tar -czvf "${BIN_NAME}_${VERSION}_linux-x64.tar.gz" "${BIN_NAME}-linux-x64"
}

release() {
set_release_action
set_files_based_on_platform
check_files_exist
do_gh_release
}

boot() {
if [ -z "$CREATE_ARCHIVES" ]; then
release
else
create_archives
fi
}

boot

0 comments on commit 374791b

Please sign in to comment.