From 073b5aaf9e0833acdbe6df34191a0213baca00a3 Mon Sep 17 00:00:00 2001 From: Aikawa Yataro Date: Sat, 3 Aug 2024 10:01:02 +0000 Subject: [PATCH] ci: add automatic releases --- .github/workflows/package.yml | 95 ++++++++++++++++++++++++++++ .github/workflows/release.yml | 49 ++++++++++++++ build/ci/package.linux.sh | 78 +++++++++++++++++++++++ build/ci/package.osx-app.sh | 22 +++++++ build/ci/package.windows-portable.sh | 19 ++++++ 5 files changed, 263 insertions(+) create mode 100644 .github/workflows/package.yml create mode 100644 .github/workflows/release.yml create mode 100755 build/ci/package.linux.sh create mode 100755 build/ci/package.osx-app.sh create mode 100755 build/ci/package.windows-portable.sh diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml new file mode 100644 index 00000000..8ffcf88e --- /dev/null +++ b/.github/workflows/package.yml @@ -0,0 +1,95 @@ +name: Package +on: + workflow_call: + inputs: + version: + description: Source Git package version + required: true + type: string +jobs: + build: + name: Build + uses: ./.github/workflows/ci.yml + windows-portable: + name: Package portable Windows app + needs: build + runs-on: ubuntu-latest + strategy: + matrix: + runtime: [win-x64, win-arm64] + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Download build + uses: actions/download-artifact@v4 + with: + name: sourcegit.${{ matrix.runtime }} + path: build/SourceGit + - name: Package + env: + VERSION: ${{ inputs.version }} + RUNTIME: ${{ matrix.runtime }} + run: ./build/ci/package.windows-portable.sh + - name: Upload package artifact + uses: actions/upload-artifact@v4 + with: + name: package.${{ matrix.runtime }} + path: build/sourcegit_*.zip + osx-app: + name: Package OSX app + needs: build + runs-on: ubuntu-latest + strategy: + matrix: + runtime: [osx-x64, osx-arm64] + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Download build + uses: actions/download-artifact@v4 + with: + name: sourcegit.${{ matrix.runtime }} + path: build/SourceGit + - name: Package + env: + VERSION: ${{ inputs.version }} + RUNTIME: ${{ matrix.runtime }} + run: ./build/ci/package.osx-app.sh + - name: Upload package artifact + uses: actions/upload-artifact@v4 + with: + name: package.${{ matrix.runtime }} + path: build/sourcegit_*.zip + linux: + name: Package Linux + needs: build + runs-on: ubuntu-latest + strategy: + matrix: + runtime: [linux-x64, linux-arm64] + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Download package dependencies + run: | + sudo add-apt-repository universe + sudo apt-get update + sudo apt-get install desktop-file-utils rpm libfuse2 + - name: Download build + uses: actions/download-artifact@v4 + with: + name: sourcegit.${{ matrix.runtime }} + path: build/SourceGit + - name: Package + env: + VERSION: ${{ inputs.version }} + RUNTIME: ${{ matrix.runtime }} + run: ./build/ci/package.linux.sh + - name: Upload package artifacts + uses: actions/upload-artifact@v4 + with: + name: package.${{ matrix.runtime }} + path: | + build/sourcegit-*.AppImage + build/sourcegit_*.deb + build/sourcegit-*.rpm diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..51e247d2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,49 @@ +name: Release +on: + push: + tags: + - v* +jobs: + version: + name: Prepare version string + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - name: Output version string + id: version + env: + TAG: ${{ github.ref_name }} + run: echo "version=${TAG#v}" >> "$GITHUB_OUTPUT" + package: + needs: version + name: Package + uses: ./.github/workflows/package.yml + with: + version: ${{ needs.version.outputs.version }} + release: + needs: [version, package] + name: Release + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Create release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAG: ${{ github.ref_name }} + run: gh release create "$TAG" -t "Release ${TAG#v}" --notes-from-tag + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + pattern: package.* + path: packages + merge-multiple: true + - name: Upload assets + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAG: ${{ github.ref_name }} + VERSION: ${{ needs.version.outputs.version }} + run: gh release upload "$TAG" packages/* diff --git a/build/ci/package.linux.sh b/build/ci/package.linux.sh new file mode 100755 index 00000000..c4c23d14 --- /dev/null +++ b/build/ci/package.linux.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +set -e + +if [ -z "$VERSION" ]; then + echo "Provide the version as environment variable VERSION" + exit 1 +fi + +if [ -z "$RUNTIME" ]; then + echo "Provide the runtime as environment variable RUNTIME" + exit 1 +fi + +arch= +appimage_arch= +appimage_runtime= +target= +case "$RUNTIME" in + linux-x64) + arch=amd64 + appimage_arch=x86_64 + appimage_runtime=runtime-fuse2-x86_64 + target=x86_64;; + linux-arm64) + arch=arm64 + appimage_arch=arm_aarch64 + appimage_runtime=runtime-fuse2-aarch64 + target=aarch64;; + *) + echo "Unknown runtime $RUNTIME" + exit 1;; +esac + +APPIMAGETOOL_URL=https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage +APPIMAGE_RUNTIME_URL=https://github.com/AppImage/type2-runtime/releases/download/old/$appimage_runtime + +cd build + +if [ ! -f "appimagetool" ]; then + curl -o appimagetool -L "$APPIMAGETOOL_URL" + chmod +x appimagetool +fi + +if [ ! -f "appimage_runtime" ]; then + curl -o appimage_runtime -L "$APPIMAGE_RUNTIME_URL" +fi + +rm -f SourceGit/*.dbg + +mkdir -p SourceGit.AppDir/opt +mkdir -p SourceGit.AppDir/usr/share/metainfo +mkdir -p SourceGit.AppDir/usr/share/applications + +cp -r SourceGit SourceGit.AppDir/opt/sourcegit +desktop-file-install resources/_common/applications/sourcegit.desktop --dir SourceGit.AppDir/usr/share/applications \ + --set-icon com.sourcegit_scm.SourceGit --set-key=Exec --set-value=AppRun +mv SourceGit.AppDir/usr/share/applications/{sourcegit,com.sourcegit_scm.SourceGit}.desktop +cp resources/appimage/sourcegit.png SourceGit.AppDir/com.sourcegit_scm.SourceGit.png +ln -sf /opt/sourcegit/sourcegit SourceGit.AppDir/AppRun +ln -rsf SourceGit.AppDir/usr/share/applications/com.sourcegit_scm.SourceGit.desktop SourceGit.AppDir +cp resources/appimage/sourcegit.appdata.xml SourceGit.AppDir/usr/share/metainfo/com.sourcegit_scm.SourceGit.appdata.xml + +ARCH="$appimage_arch" ./appimagetool -v --runtime-file appimage_runtime SourceGit.AppDir "sourcegit-$VERSION.linux.$arch.AppImage" + +mkdir -p resources/deb/opt/sourcegit/ +mkdir -p resources/deb/usr/bin +mkdir -p resources/deb/usr/share/applications +mkdir -p resources/deb/usr/share/icons +cp -f SourceGit/* resources/deb/opt/sourcegit +ln -sf ../../opt/sourcegit/sourcegit resources/deb/usr/bin +cp -r resources/_common/applications resources/deb/usr/share +cp -r resources/_common/icons resources/deb/usr/share +sed -i -e "s/^Version:.*/Version: $VERSION/" -e "s/^Architecture:.*/Architecture: $arch/" resources/deb/DEBIAN/control +dpkg-deb --root-owner-group --build resources/deb "sourcegit_$VERSION-1_$arch.deb" + +rpmbuild -bb --target="$target" resources/rpm/SPECS/build.spec --define "_topdir $(pwd)/resources/rpm" --define "_version $VERSION" +mv "resources/rpm/RPMS/$target/sourcegit-$VERSION-1.$target.rpm" ./ diff --git a/build/ci/package.osx-app.sh b/build/ci/package.osx-app.sh new file mode 100755 index 00000000..80e66a08 --- /dev/null +++ b/build/ci/package.osx-app.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +if [ -z "$VERSION" ]; then + echo "Provide the version as environment variable VERSION" + exit 1 +fi + +if [ -z "$RUNTIME" ]; then + echo "Provide the runtime as environment variable RUNTIME" + exit 1 +fi + +cd build + +mkdir -p SourceGit.app/Contents/Resources +mv SourceGit SourceGit.app/Contents/MacOS +cp resources/app/App.icns SourceGit.app/Contents/Resources/App.icns +sed "s/SOURCE_GIT_VERSION/$VERSION/g" resources/app/App.plist > SourceGit.app/Contents/Info.plist + +zip "sourcegit_$VERSION.$RUNTIME.zip" -r SourceGit.app -x "*/*\.dsym/*" diff --git a/build/ci/package.windows-portable.sh b/build/ci/package.windows-portable.sh new file mode 100755 index 00000000..cc5ee1bd --- /dev/null +++ b/build/ci/package.windows-portable.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +if [ -z "$VERSION" ]; then + echo "Provide the version as environment variable VERSION" + exit 1 +fi + +if [ -z "$RUNTIME" ]; then + echo "Provide the runtime as environment variable RUNTIME" + exit 1 +fi + +cd build + +rm -rf SourceGit/*.pdb + +zip "sourcegit_$VERSION.$RUNTIME.zip" -r SourceGit