Skip to content

Commit

Permalink
Add AUR publish step to build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
qu1ck committed Dec 4, 2023
1 parent 4c70714 commit 077e915
Show file tree
Hide file tree
Showing 2 changed files with 238 additions and 125 deletions.
284 changes: 159 additions & 125 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,138 +20,172 @@ jobs:
with:
name: dbip
path: "dbip.mmdb"
build-binaries:
# build-binaries:
# needs: download-dbip
# strategy:
# fail-fast: false
# matrix:
# platform:
# - os: ubuntu-latest
# rust_target: x86_64-unknown-linux-gnu
# - os: macos-latest
# rust_target: x86_64-apple-darwin
# - os: macos-latest
# rust_target: aarch64-apple-darwin
# - os: windows-latest
# rust_target: x86_64-pc-windows-msvc

# runs-on: ${{ matrix.platform.os }}
# steps:
# - name: Disable crlf
# if: matrix.platform.os == 'windows-latest'
# run: |
# git config --global core.autocrlf input

# - uses: actions/checkout@v3

# # Download the previously uploaded artifacts
# - uses: actions/download-artifact@v3
# id: download
# with:
# name: dbip
# path: src-tauri/

# - name: setup node
# uses: actions/setup-node@v3
# with:
# node-version: 18
# cache: 'npm'

# - name: 'Setup Rust'
# if: matrix.platform.rust_target == 'aarch64-apple-darwin'
# run: rustup target add aarch64-apple-darwin

# - uses: Swatinem/rust-cache@v2
# with:
# shared-key: ${{ matrix.platform.rust_target }}
# workspaces: |
# src-tauri

# - name: install dependencies (ubuntu only)
# if: matrix.platform.os == 'ubuntu-latest'
# run: |
# sudo apt-get update
# sudo apt-get install -y libgtk-3-dev webkit2gtk-4.0 libappindicator3-dev librsvg2-dev patchelf libasound2-dev libfontconfig-dev
# - name: install npm packages
# run: npm ci

# - uses: qu1ck/action-tauri-build@5c69c9fdbb4231a738b4a668a2caddf6af45eab8
# id: tauri_build
# with:
# target: ${{ matrix.platform.rust_target }}

# - name: Git status and version
# run: |
# git status
# git describe --tags --dirty --always
# git diff

# # The artifacts output can now be used to upload the artifacts
# - uses: actions/upload-artifact@v3
# with:
# name: ${{ matrix.platform.rust_target }}
# path: "${{ join(fromJSON(steps.tauri_build.outputs.artifacts), '\n') }}"

# - name: pack webapp
# if: matrix.platform.os == 'ubuntu-latest'
# working-directory: dist
# id: pack-webapp
# run: |
# GIT_VERSION=`git describe --tags --always`
# zip -9 -r "trguing-web-$GIT_VERSION.zip" ./* -x create\* -x \*.map -x \*flag-icons\*
# echo "ZIPFILE=trguing-web-$GIT_VERSION.zip" >> $GITHUB_OUTPUT

# - uses: actions/upload-artifact@v3
# if: matrix.platform.os == 'ubuntu-latest'
# with:
# name: build web
# path: "dist/${{ steps.pack-webapp.outputs.ZIPFILE }}"

# publish:
# needs: build-binaries
# if: startsWith(github.ref, 'refs/tags/')
# runs-on: ubuntu-latest
# permissions:
# contents: write
# steps:
# - uses: actions/checkout@v3

# # Download the previously uploaded artifacts
# - uses: actions/download-artifact@v3
# id: download
# with:
# path: artifacts
# - name: Rename mac app archives
# run: |
# mv artifacts/x86_64-apple-darwin/TrguiNG.app.tar.gz artifacts/x86_64-apple-darwin/TrguiNG_x86_64.app.tar.gz
# mv artifacts/aarch64-apple-darwin/TrguiNG.app.tar.gz artifacts/aarch64-apple-darwin/TrguiNG_aarch64.app.tar.gz
# - name: Downloaded artifacts
# run: ls -lhR artifacts/

# # Generate chagnelog
# - id: prevtag
# run: |
# PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo '')
# echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT

# - name: Generate changelog
# id: changelog
# uses: jaywcjlove/changelog-generator@main
# if: steps.prevtag.outputs.previous_tag
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# show-emoji: false

# # And create a release with the artifacts attached
# - name: 'create release'
# uses: softprops/[email protected]
# env:
# GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
# with:
# draft: true
# files: ./artifacts/**/*
# body: |
# ${{ steps.changelog.outputs.compareurl }}

# ${{ steps.changelog.outputs.changelog }}

update_aur:
name: Publish AUR package
needs: download-dbip
strategy:
fail-fast: false
matrix:
platform:
- os: ubuntu-latest
rust_target: x86_64-unknown-linux-gnu
- os: macos-latest
rust_target: x86_64-apple-darwin
- os: macos-latest
rust_target: aarch64-apple-darwin
- os: windows-latest
rust_target: x86_64-pc-windows-msvc

runs-on: ${{ matrix.platform.os }}
# needs: build-binaries
# if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Disable crlf
if: matrix.platform.os == 'windows-latest'
run: |
git config --global core.autocrlf input
- uses: actions/checkout@v3

# Download the previously uploaded artifacts
- uses: actions/download-artifact@v3
id: download
with:
name: dbip
path: src-tauri/

- name: setup node
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'

- name: 'Setup Rust'
if: matrix.platform.rust_target == 'aarch64-apple-darwin'
run: rustup target add aarch64-apple-darwin

- uses: Swatinem/rust-cache@v2
with:
shared-key: ${{ matrix.platform.rust_target }}
workspaces: |
src-tauri
- name: install dependencies (ubuntu only)
if: matrix.platform.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev webkit2gtk-4.0 libappindicator3-dev librsvg2-dev patchelf libasound2-dev libfontconfig-dev
- name: install npm packages
run: npm ci

- uses: qu1ck/action-tauri-build@5c69c9fdbb4231a738b4a668a2caddf6af45eab8
id: tauri_build
with:
target: ${{ matrix.platform.rust_target }}

- name: Git status and version
run: |
git status
git describe --tags --dirty --always
git diff
# The artifacts output can now be used to upload the artifacts
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.platform.rust_target }}
path: "${{ join(fromJSON(steps.tauri_build.outputs.artifacts), '\n') }}"

- name: pack webapp
if: matrix.platform.os == 'ubuntu-latest'
working-directory: dist
id: pack-webapp
- name: Determine version
id: determine-version
run: |
GIT_VERSION=`git describe --tags --always`
zip -9 -r "trguing-web-$GIT_VERSION.zip" ./* -x create\* -x \*.map -x \*flag-icons\*
echo "ZIPFILE=trguing-web-$GIT_VERSION.zip" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@v3
if: matrix.platform.os == 'ubuntu-latest'
with:
name: build web
path: "dist/${{ steps.pack-webapp.outputs.ZIPFILE }}"

publish:
needs: build-binaries
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3

echo "GIT_VERSION=$GIT_VERSION" >> $GITHUB_OUTPUT
# Download the previously uploaded artifacts
- uses: actions/download-artifact@v3
id: download
with:
path: artifacts
- name: Rename mac app archives
run: |
mv artifacts/x86_64-apple-darwin/TrguiNG.app.tar.gz artifacts/x86_64-apple-darwin/TrguiNG_x86_64.app.tar.gz
mv artifacts/aarch64-apple-darwin/TrguiNG.app.tar.gz artifacts/aarch64-apple-darwin/TrguiNG_aarch64.app.tar.gz
- name: Downloaded artifacts
run: ls -lhR artifacts/

# Generate chagnelog
- id: prevtag
name: dbip
- name: Download desktop file
run: wget -nv -O TrguiNG.desktop "https://raw.githubusercontent.com/flathub/org.openscopeproject.TrguiNG/master/org.openscopeproject.TrguiNG.desktop"
- name: Generate PKGBUILD
run: |
PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo '')
echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
- name: Generate changelog
id: changelog
uses: jaywcjlove/changelog-generator@main
if: steps.prevtag.outputs.previous_tag
with:
token: ${{ secrets.GITHUB_TOKEN }}
show-emoji: false

# And create a release with the artifacts attached
- name: 'create release'
uses: softprops/[email protected]
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
with:
draft: true
files: ./artifacts/**/*
body: |
${{ steps.changelog.outputs.compareurl }}
${{ steps.changelog.outputs.changelog }}
python3 ci/generate_pkgbuild.py
cat PKGBUILD
# - name: Publish to the AUR
# uses: KSXGitHub/[email protected]
# with:
# pkgname: trgui-ng
# pkgbuild: ./PKGBUILD
# commit_username: ${{ secrets.AUR_USERNAME }}
# commit_email: ${{ secrets.AUR_EMAIL }}
# ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
# commit_message: Update to ${{ steps.determine-version.outputs.GIT_VERSION }}
# force_push: 'true'
79 changes: 79 additions & 0 deletions ci/generate_pkgbuild.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import os
import subprocess

if "GITHUB_REF" not in os.environ:
print("GITHUB_REF variable not set")
exit(1)

REF = os.environ.get("GITHUB_REF")
if REF is None or not REF.startswith("refs/tags/v"):
print("Invalid version ref:", REF)
exit(1)

VERSION = REF[len("refs/tags/v"):]

with subprocess.Popen(["sha256sum", "dbip.mmdb"], stdout=subprocess.PIPE) as proc:
DBIP_SHA = proc.stdout.read().decode()[:64]
with subprocess.Popen(["sha256sum", "TrguiNG.desktop"], stdout=subprocess.PIPE) as proc:
DESKTOP_SHA = proc.stdout.read().decode()[:64]


TEMPLATE = '''
# MAINTAINER username227 gfrank227[at]gmail[dot]com
# MAINTAINER qu1ck anlutsenko[at]gmail[dot]com
pkgname=trgui-ng
pkgver='%VERSION%'
pkgrel=1
pkgdesc='Remote GUI for Transmission torrent daemon'
url="https://github.com/openscopeproject/TrguiNG"
arch=('x86_64')
license=('AGPL-3.0')
depends=('alsa-lib' 'cairo' 'desktop-file-utils' 'fontconfig' 'gdk-pixbuf2' 'glib2' 'gtk3' 'hicolor-icon-theme' 'libayatana-appindicator' 'libsoup' 'openssl' 'webkit2gtk')
makedepends=('rust>=1.69.0' 'nodejs>=16.0.0')
source=("git+https://github.com/openscopeproject/TrguiNG#tag=v$pkgver"
"https://github.com/openscopeproject/TrguiNG/releases/download/v$pkgver/dbip.mmdb"
"TrguiNG.desktop"::"https://raw.githubusercontent.com/flathub/org.openscopeproject.TrguiNG/master/org.openscopeproject.TrguiNG.desktop")
noextract=('dbip.mmdb')
sha256sums=('SKIP'
'%DBIP_SHA256%'
'%DESKTOP_SHA256%')
prepare() {
cd "$srcdir/TrguiNG"
cp "../dbip.mmdb" "src-tauri/dbip.mmdb"
}
build() {
cd "$srcdir/TrguiNG"
npm install
npm run build -- -b
}
package() {
install -dm755 "$pkgdir/usr/bin"
install -dm755 "$pkgdir/usr/lib/trgui-ng"
install -dm755 "$pkgdir/usr/share/icons/hicolor/32x32/apps"
install -dm755 "$pkgdir/usr/share/icons/hicolor/128x128/apps"
install -Dm755 "$srcdir/TrguiNG/src-tauri/target/release/trgui-ng" "$pkgdir/usr/bin/trgui-ng"
install -Dm644 "$srcdir/TrguiNG/src-tauri/dbip.mmdb" "$pkgdir/usr/lib/trgui-ng/dbip.mmdb"
install -Dm755 "$srcdir/TrguiNG.desktop" "$pkgdir/usr/share/applications/TrguiNG.desktop"
install -Dm644 "$srcdir/TrguiNG/src-tauri/icons/32x32.png" "$pkgdir/usr/share/icons/hicolor/32x32/apps/trgui-ng.png"
install -Dm644 "$srcdir/TrguiNG/src-tauri/icons/128x128.png" "$pkgdir/usr/share/icons/hicolor/128x128/apps/trgui-ng.png"
install -Dm644 "$srcdir/TrguiNG/src-tauri/icons/app.svg" "$pkgdir/usr/share/icons/hicolor/scalable/apps/trgui-ng.svg"
}
'''

TEMPLATE_VALUES = {
"%VERSION%": VERSION,
"%DBIP_SHA256%": DBIP_SHA,
"%DESKTOP_SHA256%": DESKTOP_SHA,
}

pkgbuild = TEMPLATE[1:]
for k, v in TEMPLATE_VALUES.items():
pkgbuild = pkgbuild.replace(k, v)

with open("PKGBUILD", "w") as f:
f.write(pkgbuild)

0 comments on commit 077e915

Please sign in to comment.