Skip to content

Commit

Permalink
feat(ci): 添加构建脚本,调整github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
qwertyyb committed Oct 28, 2020
1 parent 2a4f5ac commit 945b75f
Show file tree
Hide file tree
Showing 15 changed files with 327 additions and 107 deletions.
80 changes: 49 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,69 @@ on:
types: ['published']

jobs:
release:
build:
runs-on: macOS-latest

steps:
- uses: actions/checkout@v1

- name: update version
run: |
PRODUCT_SETTINGS_PATH=./Fire/Info.plist
version=$(git describe --tags `git rev-list --tags --max-count=1`)
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $version" $PRODUCT_SETTINGS_PATH
- uses: actions/checkout@v2

- name: switch xcode version
run: sudo xcode-select --switch /Applications/Xcode_12.app

- name: install depencies
run: pod install
- name: archive
run: xcodebuild archive -workspace Fire.xcworkspace -scheme Fire -archivePath ./archive-Fire -configuration Release
- name: copy app && zip app && generate appcast

- name: build
run: ./build_app.sh

- name: make FireInstaller.pkg
run: ./package/make_package.sh

- name: generate appcast.xml
env:
sparkle_key: ${{ secrets.sparkle_key }}
run: |
mkdir apps
cp -a ./archive-Fire.xcarchive/Products/Applications/*.app apps
ditto -c -k --sequesterRsrc --keepParent apps/Fire.app apps/Fire.zip
# rm -r ~/Library/Caches/Sparkle_generate_appcast/*
./bin/generate_appcast -s $sparkle_key ./apps/
run: ./build_appcast.sh

- name: package to .pkg file
run: |
version=$(git describe --tags `git rev-list --tags --max-count=1`)
pkgbuild --component ./apps/Fire.app --install-location /Library/Input\ Methods --identifier com.qwertyyb.pkg.FireInstaller --version $version ./apps/FireInstaller.pkg
- name: gather artifact
run: cp ./Fire/Info.plist ./apps/

- uses: actions/upload-artifact@v2
with:
name: apps
path: ./apps/

- name: release
publish:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v2

- uses: actions/download-artifact@v2
with:
name: apps
path: ./apps


- name: upload release assets
uses: AButler/upload-release-assets@v1.0
with:
files: 'apps/Fire.zip,apps/FireInstaller.pkg'
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: install & config coscmd
env:
oss_appid: ${{ secrets.oss_appid }}
oss_secret: ${{ secrets.oss_secret }}

- name: move artifact
run: |
pip install pip==9.0.0 && pip install coscmd
coscmd config -a $oss_appid -s $oss_secret -b person-1253524658 -r ap-beijing
- name: upload app and appcast
mv apps/appcast.xml ./appcast.xml
mv apps/Info.plist ./Fire/
- name: remove useless file
run: rm -rf ./apps

- name: commit appcast.xml
run: |
coscmd upload ./apps/Fire.zip cloudfn/apps/fire/Fire.zip
coscmd upload ./apps/appcast.xml cloudfn/apps/fire/appcast.xml
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git pull origin master
git add .
git commit -m "chore: update version"
git push origin HEAD:master
29 changes: 19 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,30 @@ on:
- '**'

jobs:
test:
build-test:
runs-on: macOS-latest

steps:
- uses: actions/checkout@v1

- name: switch xcode version
run: sudo xcode-select --switch /Applications/Xcode_12.app

- name: install depencies
run: pod install
- name: archive
run: xcodebuild archive -workspace Fire.xcworkspace -scheme Fire -archivePath ./archive-Fire -configuration Release
- name: copy app && zip app && generate appcast

- name: build
run: ./build_app.sh

- name: make FireInstaller.pkg
run: ./package/make_package.sh

- name: generate appcast.xml
env:
sparkle_key: ${{ secrets.sparkle_key }}
run: |
mkdir apps
cp -a ./archive-Fire.xcarchive/Products/Applications/*.app apps
ditto -c -k --sequesterRsrc --keepParent apps/Fire.app apps/Fire.zip
# rm -r ~/Library/Caches/Sparkle_generate_appcast/*
./bin/generate_appcast -s $sparkle_key ./apps/
run: ./build_appcast.sh

- uses: actions/upload-artifact@v2
with:
name: apps
path: ./apps/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

/apps
/*.xcarchive
/*.log
/package/*.pkg

# Created by https://www.gitignore.io/api/swift,macos
# Edit at https://www.gitignore.io/?templates=swift,macos
Expand Down
31 changes: 8 additions & 23 deletions Fire.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
459DE990232EB26600A3ACD1 /* CandidatesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 459DE98E232EB26500A3ACD1 /* CandidatesView.swift */; };
459DE991232EB26600A3ACD1 /* CandidatesWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 459DE98F232EB26500A3ACD1 /* CandidatesWindow.swift */; };
45D996AA253C5232001460A8 /* PreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45D996A9253C5232001460A8 /* PreferencesView.swift */; };
673A400C253D9FE70003901E /* InputSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 673A400B253D9FE70003901E /* InputSource.swift */; };
673CD81C233DCF14006538B8 /* table.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 673CD81B233DCF14006538B8 /* table.sqlite */; };
67E8B515233B97FD00D7CE80 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 67E8B517233B97FD00D7CE80 /* InfoPlist.strings */; };
67E8B521233C537B00D7CE80 /* fire.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 67E8B51E233C537B00D7CE80 /* fire.pdf */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
060E0C2FC1C04AEFD80DD621 /* libPods-Fire.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Fire.a"; sourceTree = BUILT_PRODUCTS_DIR; };
451E6044232E227B007B0463 /* Fire.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Fire.app; sourceTree = BUILT_PRODUCTS_DIR; };
451E6047232E227B007B0463 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
451E604F232E227C007B0463 /* Fire.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Fire.entitlements; sourceTree = "<group>"; };
Expand All @@ -36,7 +38,7 @@
459DE98F232EB26500A3ACD1 /* CandidatesWindow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CandidatesWindow.swift; sourceTree = "<group>"; };
45D996A9253C5232001460A8 /* PreferencesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesView.swift; sourceTree = "<group>"; };
497E90F13FA9A943AC0BE3DB /* Pods-Fire.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Fire.release.xcconfig"; path = "Target Support Files/Pods-Fire/Pods-Fire.release.xcconfig"; sourceTree = "<group>"; };
59F80EA93E8AE7885721524F /* libPods-Fire.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Fire.a"; sourceTree = BUILT_PRODUCTS_DIR; };
673A400B253D9FE70003901E /* InputSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputSource.swift; sourceTree = "<group>"; };
673CD81B233DCF14006538B8 /* table.sqlite */ = {isa = PBXFileReference; lastKnownFileType = file; path = table.sqlite; sourceTree = "<group>"; };
67E8B511233B978E00D7CE80 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
67E8B516233B97FD00D7CE80 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -101,6 +103,7 @@
451E605E232E400B007B0463 /* Fire.swift */,
45587F2C24E8FBFB005F291B /* Utils.swift */,
45D996A9253C5232001460A8 /* PreferencesView.swift */,
673A400B253D9FE70003901E /* InputSource.swift */,
);
path = Fire;
sourceTree = "<group>";
Expand All @@ -109,7 +112,7 @@
isa = PBXGroup;
children = (
451E6058232E2787007B0463 /* InputMethodKit.framework */,
59F80EA93E8AE7885721524F /* libPods-Fire.a */,
060E0C2FC1C04AEFD80DD621 /* libPods-Fire.a */,
);
name = Frameworks;
sourceTree = "<group>";
Expand All @@ -134,7 +137,6 @@
451E6041232E227B007B0463 /* Frameworks */,
451E6042232E227B007B0463 /* Resources */,
CC4E3CB56A41B3947C0BFEC1 /* [CP] Embed Pods Frameworks */,
45449B4D235360B900C9EFEF /* update version */,
45587F2E24E91513005F291B /* lint */,
);
buildRules = (
Expand Down Expand Up @@ -201,24 +203,6 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
45449B4D235360B900C9EFEF /* update version */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "update version";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "version=`/usr/libexec/PlistBuddy -c \"Print CFBundleVersion\" $PRODUCT_SETTINGS_PATH`\nversion=`expr $version + 1`\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $version\" $PRODUCT_SETTINGS_PATH\n";
};
45587F2E24E91513005F291B /* lint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -288,6 +272,7 @@
45587F2D24E8FBFB005F291B /* Utils.swift in Sources */,
45D996AA253C5232001460A8 /* PreferencesView.swift in Sources */,
451E6048232E227B007B0463 /* AppDelegate.swift in Sources */,
673A400C253D9FE70003901E /* InputSource.swift in Sources */,
459DE991232EB26600A3ACD1 /* CandidatesWindow.swift in Sources */,
459DE990232EB26600A3ACD1 /* CandidatesView.swift in Sources */,
);
Expand Down Expand Up @@ -440,7 +425,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CONFIGURATION_BUILD_DIR = "/Library/Input Methods";
DEVELOPMENT_TEAM = T68XK6867P;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Fire/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -464,7 +449,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = T68XK6867P;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Fire/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down
45 changes: 11 additions & 34 deletions Fire/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,18 @@ class AppDelegate: NSObject, NSApplicationDelegate {
fire = Fire.shared
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
let installedLocationURL = CFURLCreateFromFileSystemRepresentation(
nil,
"/Library/Input Methods/Fire.app",
"/Library/Input Methods/Fire.app".count,
false
)
let kSourceID = "com.qwertyyb.inputmethod.Fire"

let kInputModeID = "com.qwertyyb.inputmethod.Fire"

if installedLocationURL != nil {
TISRegisterInputSource(installedLocationURL)
}

let sourceList = TISCreateInputSourceList(nil, true)

for index in 0...CFArrayGetCount(sourceList!.takeUnretainedValue())-1 {
// sourceList?.takeUnretainedValue()
let inputSource = Unmanaged<TISInputSource>.fromOpaque(CFArrayGetValueAtIndex(
sourceList?.takeUnretainedValue(), index)).takeUnretainedValue()
let ptr = TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceID)
let sourceID = Unmanaged<CFString>.fromOpaque(ptr!).takeUnretainedValue() as NSString
// NSLog("examining input source '%@", sourceID);
if (sourceID.isEqual(to: kSourceID) ) || sourceID.isEqual(to: kInputModeID) {
TISEnableInputSource(inputSource)
NSLog("Enabled input source: %@", sourceID)
let isSelectable = Unmanaged<CFBoolean>.fromOpaque(TISGetInputSourceProperty(
inputSource, kTISPropertyInputSourceIsSelectCapable)).takeUnretainedValue()
if CFBooleanGetValue(isSelectable) {
TISSelectInputSource(inputSource)
NSLog("Selected input source: %@", sourceID)
}
}
if CommandLine.arguments.count > 1 {
print("[Fire] launch argument: \(CommandLine.arguments[1])")
if CommandLine.arguments[1] == "--install" {
print("install input source")
registerInputSource()
deactivateInputSource()
activateInputSource()
NSApp.terminate(nil)
return
}
}
NSLog("lanched")
NSLog("launch input source")
}

func applicationWillTerminate(_ aNotification: Notification) {
Expand Down
6 changes: 3 additions & 3 deletions Fire/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.0.1</string>
<string>v0.0.3</string>
<key>CFBundleURLTypes</key>
<array>
<dict/>
</array>
<key>CFBundleVersion</key>
<string>742</string>
<string>777</string>
<key>ComponentInputModeDict</key>
<dict>
<key>tsInputModeListKey</key>
Expand Down Expand Up @@ -87,7 +87,7 @@
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>SUFeedURL</key>
<string>https://cdn.qwertyyb.cn/cloudfn/apps/fire/appcast.xml</string>
<string>https://raw.githubusercontent.com/qwertyyb/Fire/master/appcast.xml</string>
<key>SUPublicEDKey</key>
<string>tR/BZ1M7WhteABLgJDf3f/bsxUHYMPABoY9PuPvI0TE=</string>
<key>tsInputMethodCharacterRepertoireKey</key>
Expand Down
62 changes: 62 additions & 0 deletions Fire/InputSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// InputSource.swift
// Fire
//
// Created by marchyang on 2020/10/19.
// Copyright © 2020 qwertyyb. All rights reserved.
//

import Carbon

let installLocation = "/Library/Input Methods/Fire.app"
let kSourceID = "com.qwertyyb.inputmethod.Fire"
let kInputModeID = "com.qwertyyb.inputmethod.Fire"

func registerInputSource() {
let installedLocationURL = CFURLCreateFromFileSystemRepresentation(
nil,
installLocation,
installLocation.count,
false
)
if installedLocationURL != nil {
TISRegisterInputSource(installedLocationURL)
NSLog("register input source")
}
}

func activateInputSource() {
let sourceList = TISCreateInputSourceList(nil, true)

for index in 0...CFArrayGetCount(sourceList!.takeUnretainedValue())-1 {
let inputSource = Unmanaged<TISInputSource>.fromOpaque(CFArrayGetValueAtIndex(
sourceList?.takeUnretainedValue(), index)).takeUnretainedValue()
let ptr = TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceID)
let sourceID = Unmanaged<CFString>.fromOpaque(ptr!).takeUnretainedValue() as NSString
if (sourceID.isEqual(to: kSourceID) ) || sourceID.isEqual(to: kInputModeID) {
TISEnableInputSource(inputSource)
NSLog("Enabled input source: %@", sourceID)
let isSelectable = Unmanaged<CFBoolean>.fromOpaque(TISGetInputSourceProperty(
inputSource, kTISPropertyInputSourceIsSelectCapable)).takeUnretainedValue()
if CFBooleanGetValue(isSelectable) {
TISSelectInputSource(inputSource)
NSLog("Selected input source: %@", sourceID)
}
}
}
}

func deactivateInputSource() {
let sourceList = TISCreateInputSourceList(nil, true)

for index in 0...CFArrayGetCount(sourceList!.takeUnretainedValue())-1 {
let inputSource = Unmanaged<TISInputSource>.fromOpaque(CFArrayGetValueAtIndex(
sourceList?.takeUnretainedValue(), index)).takeUnretainedValue()
let ptr = TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceID)
let sourceID = Unmanaged<CFString>.fromOpaque(ptr!).takeUnretainedValue() as NSString
if (sourceID.isEqual(to: kSourceID) ) || sourceID.isEqual(to: kInputModeID) {
TISDisableInputSource(inputSource)
NSLog("Disable input source: %@", sourceID)
}
}
}
Loading

0 comments on commit 945b75f

Please sign in to comment.