Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

perf(Injector): use semaphore and URLSession to download remote resource #101

perf(Injector): use semaphore and URLSession to download remote resource

perf(Injector): use semaphore and URLSession to download remote resource #101

Workflow file for this run

name: CI - Build Application
on:
push:
branches:
- 'main'
paths-ignore:
- 'LICENSE'
- '**.md'
pull_request:
release:
types: [created]
workflow_dispatch:
permissions:
write-all
jobs:
build-mac:
name: Build for macOS (Universal)
runs-on: macOS-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# - name: Set node
# uses: actions/setup-node@v4
# with:
# node-version: 20.x
# - name: Set up Homebrew
# id: set-up-homebrew
# uses: Homebrew/actions/setup-homebrew@master
# - name: Install dependencies
# run: |
# brew install graphicsmagick imagemagick
- name: Set up env.APP_CONF to Debug
if: github.event_name != 'release'
run: |
echo "APP_CONF=Debug" >> $GITHUB_ENV
- name: Set up env.APP_CONF to Release
if: github.event_name == 'release'
run: |
echo "APP_CONF=Release" >> $GITHUB_ENV
APP_VERSION=$(xcrun agvtool mvers -terse1)
APP_BUILD=$(xcrun agvtool vers -terse)
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
echo "APP_BUILD=$APP_BUILD" >> $GITHUB_ENV
- name: Build for macOS (Universal)
shell: bash
run: |
xcodebuild -project 'InjectGUI.xcodeproj' -scheme 'InjectGUI' -configuration '${{ env.APP_CONF }}' -destination 'platform=macOS' build -derivedDataPath 'build'
- name: Create DMG
shell: bash
run: |
hdiutil create -volname "InjectGUI" -srcfolder "build/Build/Products/${{ env.APP_CONF }}/InjectGUI.app" -ov -format UDZO "InjectGUI.dmg"
cp "InjectGUI.dmg" "$RUNNER_TEMP/InjectGUI.dmg"
- name: Upload DMG Artifact
id: upload-artifact
uses: actions/upload-artifact@v4
with:
name: InjectGUI
path: InjectGUI.dmg
- name: Upload DMG to GitHub Release
if: github.event_name == 'release'
uses: softprops/action-gh-release@v2
with:
files: InjectGUI.dmg
############################
# Sparkle Appcast
############################
- name: Update Sparkle appcast
if: github.event_name == 'release'
env:
# SPARKLE_KEY: Sparkle EdDSA key exported from `generate_keys -x` as plain text
# SPARKLE_CHANNEL: Seperate dev builds from default channel, to be specified in [SPUUpdaterDelegate allowedChannelsForUpdater:]
# SPARKLE_DL_PREFIX: Prefix for the URL from where updates will be downloaded
# SPARKLE_LINK: CodeEdit Website
# https://github.com/wibus-wee/InjectGUI/releases/download/0.0.1-alpha.11/CodeEdit-9113dc5.dmg
# RELEASE_NOTES_PREFIX: The URL to prefix before an update link:
# https://codeedit.app/whats-new/raw/{v0.1.0} -- data in {} is inserted by sparkle
# RELEASE_NOTES_URL: The URL of the entire release notes page: https://codeedit.app/whats-new
SPARKLE_KEY: ${{ secrets.SPARKLE_KEY }}
# SPARKLE_CHANNEL: dev
SPARKLE_DL_PREFIX: "https://github.com/wibus-wee/InjectGUI/releases/download"
SPARKLE_LINK: "https://github.com/wibus-wee/InjectGUI"
APP_VERSION: ${{ env.APP_VERSION }}
APP_BUILD: ${{ env.APP_BUILD }}
# RELEASE_NOTES_URL: "https://codeedit.app/whats-new/"
# RELEASE_NOTES_PREFIX: "https://codeedit.app/sparkle/"
run: |
SPARKLE_BIN="$RUNNER_TEMP/build/SourcePackages/artifacts/sparkle/Sparkle/bin"
SPARKLE_ARCHIVE="$RUNNER_TEMP/Sparkle_Archive"
echo -n "$SPARKLE_KEY" | tee "$RUNNER_TEMP/sparkle_key"
mkdir "$SPARKLE_ARCHIVE"
cp "$RUNNER_TEMP/InjectGUI.dmg" "$SPARKLE_ARCHIVE"
SPARKLE_SIG=$("$SPARKLE_BIN/sign_update" --ed-key-file "$RUNNER_TEMP/sparkle_key" "$SPARKLE_ARCHIVE/InjectGUI.dmg" | cut -d\" -f2)
echo "<!DOCTYPE>" > "$SPARKLE_ARCHIVE/InjectGUI.html" # Need a blank html doc with the DOCTYPE tag to trick sparkle into loading our remote release notes.
"$SPARKLE_BIN/generate_appcast" --ed-key-file "$RUNNER_TEMP/sparkle_key" --download-url-prefix "${{ env.SPARKLE_DL_PREFIX }}/v${{ env.APP_VERSION }}/" --link "$SPARKLE_LINK" --maximum-deltas 0 "$SPARKLE_ARCHIVE"
- name: Upload Sparkle Appcast
if: github.event_name == 'release'
uses: softprops/action-gh-release@v2
with:
files: "${{ RUNNER.TEMP }}/Sparkle_Archive/appcast.xml"
- name: Upload Sparkle Artifact
if: github.event_name == 'release'
uses: actions/upload-artifact@v4
with:
name: appcast.xml
path: "${{ RUNNER.TEMP }}/Sparkle_Archive/appcast.xml"
- name: Find Comment
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: 'InjectGUI'
- name: Gen Previous Builds List
if: github.event_name == 'pull_request'
run: |
shas_and_links=$(echo "${{ steps.fc.outputs.comment-body }}" | sed -n 's/.*\[\([^!][^]]*\)\].*/\1/p')
result_list=""
IFS=',' # 设置内部字段分隔符为逗号
for entry in $shas_and_links; do
sha=$(echo "$entry" | cut -d';' -f1)
link=$(echo "$entry" | cut -d';' -f2)
result_list+="<sup><li><a href='${link}'>${sha}</a></li></sup>"
done
echo "PREVIOUS_BUILDS=${result_list}" >> $GITHUB_ENV
- name: Add new build to Previous Builds List
if: github.event_name == 'pull_request'
run: |
new_sha="${{github.sha}}"
new_link="${{ steps.upload-artifact.outputs.artifact-id }}"
new_link="https://github.com/wibus-wee/InjectGUI/actions/runs/${{ github.run_id }}/artifacts/${new_link}"
comment_body="${{ steps.fc.outputs.comment-body }}"
if [ -z "$new_link" ]; then
echo "Artifact URL is empty. Skipping update."
else
shas_and_links=$(echo "$comment_body" | sed -n 's/.*\[\([^!][^]]*\)\].*/\1/p')
shas_and_links="${shas_and_links},[${new_sha};${new_link}]"
echo "NEW_COMMENT_LIST=${shas_and_links}" >> $GITHUB_ENV
fi
- name: Create Pull Request Comment
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
with:
edit-mode: replace
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Hi, thanks for your contribution!
**InjectGUI** (${{ github.sha }}) has been built and is available for download to test. (Based on PR ${{ github.event.pull_request.number }})
You can download the latest artifact from here: https://github.com/wibus-wee/InjectGUI/actions/runs/${{ github.run_id }}/artifacts/${{ steps.upload-artifact.outputs.artifact-id }}
> [!WARNING]
> This is a PR build and may not be stable. It's only for testing purposes.
---
<!--${{ env.NEW_COMMENT_LIST }}-->
<sup>Previous builds:</sup>
${{ env.PREVIOUS_BUILDS }}