Skip to content
This repository was archived by the owner on Feb 4, 2024. It is now read-only.

Commit 64c7e4b

Browse files
committed
👷 add build workflow
1 parent de5fca8 commit 64c7e4b

4 files changed

Lines changed: 188 additions & 8 deletions

File tree

.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
APP_VERSION=1.0.3
2-
GITHUB_REPOSITORY_URL=https://github.com/techouse/alfred-stackexchange
3-
STACK_EXCHANGE_API_VERSION=2.3
1+
APP_VERSION=
2+
GITHUB_REPOSITORY_URL=
3+
STACK_EXCHANGE_API_VERSION=
44
STACK_EXCHANGE_API_KEY=
55
STACK_EXCHANGE_CLIENT_ID=

.github/workflows/build.yml

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
name: Build package
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+*'
7+
defaults:
8+
run:
9+
shell: bash
10+
env:
11+
PUB_ENVIRONMENT: bot.github
12+
permissions: read-all
13+
14+
jobs:
15+
publish:
16+
name: "Build"
17+
runs-on: macos-latest
18+
environment: build
19+
permissions:
20+
contents: write
21+
env:
22+
GITHUB_REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }}
23+
steps:
24+
- uses: dart-lang/setup-dart@v1
25+
with:
26+
sdk: stable
27+
- id: checkout
28+
uses: actions/checkout@v3
29+
- name: Compare version with ref/tag
30+
if: startsWith(github.ref, 'refs/tags/')
31+
id: compare_version_with_tag
32+
run: |
33+
set -e
34+
VERSION=$(awk '/^version: / {print $2}' pubspec.yaml)
35+
TAG=${GITHUB_REF_NAME#v}
36+
if [[ "$VERSION" != "$TAG" ]]; then
37+
echo "Version in pubspec.yaml ($VERSION) does not match tag ($TAG)"
38+
exit 1
39+
fi
40+
echo "VERSION=$VERSION" >> $GITHUB_ENV
41+
- name: Configure .env file
42+
id: generate_env_file
43+
env:
44+
STACK_EXCHANGE_API_KEY: ${{ vars.STACK_EXCHANGE_API_KEY }}
45+
STACK_EXCHANGE_API_VERSION: ${{ vars.STACK_EXCHANGE_API_VERSION }}
46+
STACK_EXCHANGE_CLIENT_ID: ${{ vars.STACK_EXCHANGE_CLIENT_ID }}
47+
run: |
48+
set -e
49+
mv .env.example .env
50+
sed -i '' "s#APP_VERSION=.*#APP_VERSION=$VERSION#" .env
51+
sed -i '' "s#GITHUB_REPOSITORY_URL=.*#GITHUB_REPOSITORY_URL=$GITHUB_REPOSITORY_URL#" .env
52+
sed -i '' "s#STACK_EXCHANGE_API_VERSION=.*#STACK_EXCHANGE_API_VERSION=$STACK_EXCHANGE_API_VERSION#" .env
53+
sed -i '' "s#STACK_EXCHANGE_API_KEY=.*#STACK_EXCHANGE_API_KEY=$STACK_EXCHANGE_API_KEY#" .env
54+
sed -i '' "s#STACK_EXCHANGE_CLIENT_ID=.*#STACK_EXCHANGE_CLIENT_ID=$STACK_EXCHANGE_CLIENT_ID#" .env
55+
- name: Configure the info.plist
56+
id: info_plist
57+
run: |
58+
set -e
59+
/usr/libexec/PlistBuddy -c "Set :version $VERSION" ./info.plist
60+
/usr/libexec/PlistBuddy -c "Set :webaddress $GITHUB_REPOSITORY_URL" ./info.plist
61+
- name: Install dependencies
62+
id: install_dependencies
63+
run: |
64+
dart pub get
65+
dart pub global activate -sgit https://github.com/techouse/dart_pubspec_licenses_lite
66+
- name: Run Dart code generation
67+
id: generate_code
68+
run: dart run build_runner build --delete-conflicting-outputs
69+
- name: Check formatting
70+
run: dart format --output=none --set-exit-if-changed .
71+
- name: Analyze
72+
run: dart analyze --fatal-infos
73+
- name: Build executable
74+
id: build_executable
75+
run: bash ./build.sh
76+
- name: Install the Apple certificate
77+
id: install_certificate
78+
env:
79+
BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }}
80+
P12_PASSWORD: ${{ secrets.P12_PASSWORD }}
81+
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
82+
run: |
83+
set -e
84+
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
85+
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
86+
87+
# import certificate
88+
echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode -o $CERTIFICATE_PATH
89+
90+
# create temporary keychain
91+
security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
92+
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
93+
security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
94+
95+
# import certificate to keychain
96+
security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
97+
security list-keychain -d user -s $KEYCHAIN_PATH
98+
- name: Sign executable
99+
id: sign_executable
100+
env:
101+
BUILD_CERTIFICATE_SHA1: ${{ secrets.BUILD_CERTIFICATE_SHA1 }}
102+
run: |
103+
set -e
104+
BUNDLE_ID=$(/usr/libexec/PlistBuddy -c 'print ":bundleid"' info.plist)
105+
codesign \
106+
--sign="$BUILD_CERTIFICATE_SHA1" \
107+
--identifier="$BUNDLE_ID" \
108+
--deep \
109+
--force \
110+
--options=runtime \
111+
--entitlement="./entitlements.plist" \
112+
--timestamp \
113+
./build/dist/workflow
114+
- name: Verify signature
115+
id: verify_executable_signature
116+
env:
117+
TEAM_ID: ${{ secrets.TEAM_ID }}
118+
run: |
119+
set -e
120+
if [[ $(codesign -dv ./build/dist/workflow 2>&1 | awk -F= '/TeamIdentifier/{print $2}') != "$TEAM_ID" ]]; then
121+
echo "The TeamIdentifier in the signature does not match the signing TeamIdentifier."
122+
exit 1
123+
fi
124+
- name: Package executable into ZIP archive
125+
id: zip_executable
126+
run: |
127+
set -e
128+
zip -j ./build/dist/workflow.zip ./build/dist/workflow
129+
- name: Create notarytool Keychain profile
130+
id: create_keychain_profile
131+
env:
132+
APPLE_ID: ${{ secrets.APPLE_ID }}
133+
TEAM_ID: ${{ secrets.TEAM_ID }}
134+
NOTARYTOOL_PASSWORD: ${{ secrets.NOTARYTOOL_PASSWORD }}
135+
NOTARYTOOL_KEYCHAIN_PROFILE: ${{ vars.NOTARYTOOL_KEYCHAIN_PROFILE }}
136+
run: |
137+
set -e
138+
xcrun notarytool \
139+
store-credentials "$NOTARYTOOL_KEYCHAIN_PROFILE" \
140+
--apple-id "$APPLE_ID" \
141+
--team-id "$TEAM_ID" \
142+
--password "$NOTARYTOOL_PASSWORD"
143+
- name: Notarize executable
144+
id: notarize_executable
145+
env:
146+
NOTARYTOOL_KEYCHAIN_PROFILE: ${{ vars.NOTARYTOOL_KEYCHAIN_PROFILE }}
147+
run: |
148+
set -e
149+
xcrun notarytool \
150+
submit ./build/dist/workflow.zip \
151+
--keychain-profile "$NOTARYTOOL_KEYCHAIN_PROFILE" \
152+
--wait
153+
- name: Delete obsolete ZIP archive
154+
id: delete_zip_archive
155+
run: |
156+
set -e
157+
rm -rf ./build/dist/workflow.zip
158+
- name: Create Alfred Workflow
159+
id: create_alfred_workflow
160+
env:
161+
WORKFLOW_NAME: ${{ vars.WORKFLOW_NAME }}
162+
run: |
163+
set -e
164+
pushd ./build/dist || exit 1
165+
find . -not -path "./*_cache*" -exec zip --symlinks "../${WORKFLOW_NAME}-v${VERSION}.alfredworkflow" {} +
166+
popd || exit 1
167+
echo "artifactPath=build/${WORKFLOW_NAME}-v${VERSION}.alfredworkflow" >> $GITHUB_ENV
168+
- name: Release
169+
id: release_workflow
170+
uses: softprops/action-gh-release@v1
171+
with:
172+
files: ${{ env.artifactPath }}
173+
- name: Clean up keychain and build directory
174+
id: clean_up
175+
if: ${{ always() }}
176+
run: |
177+
security delete-keychain $RUNNER_TEMP/app-signing.keychain-db
178+
rm -rf $RUNNER_TEMP/build_certificate.p12
179+
rm .env
180+
rm -rf ./build

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ else
3636
echo 'Info: Unable to generate OSS LICENSES. Please install https://github.com/techouse/dart_pubspec_licenses_lite'
3737
fi
3838

39-
dart compile exe bin/main.dart -o build/dist/so -S build/debug_info/so
39+
dart compile exe bin/main.dart -o build/dist/workflow -S build/debug_info/workflow

info.plist

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<key>escaping</key>
6666
<integer>102</integer>
6767
<key>script</key>
68-
<string>arch -x86_64 ./so -u</string>
68+
<string>arch -x86_64 ./workflow -u</string>
6969
<key>scriptargtype</key>
7070
<integer>1</integer>
7171
<key>scriptfile</key>
@@ -108,7 +108,7 @@
108108
<key>runningsubtext</key>
109109
<string>Fetching StackOverflow questions ...</string>
110110
<key>script</key>
111-
<string>arch -x86_64 ./so -q "{query}"</string>
111+
<string>arch -x86_64 ./workflow -q "{query}"</string>
112112
<key>scriptargtype</key>
113113
<integer>0</integer>
114114
<key>scriptfile</key>
@@ -221,8 +221,8 @@
221221
<key>variablesdontexport</key>
222222
<array/>
223223
<key>version</key>
224-
<string>1.0.3</string>
224+
<string></string>
225225
<key>webaddress</key>
226-
<string>https://github.com/techouse/alfred-stackoverflow</string>
226+
<string></string>
227227
</dict>
228228
</plist>

0 commit comments

Comments
 (0)