Skip to content

Commit

Permalink
feat: add snap build
Browse files Browse the repository at this point in the history
  • Loading branch information
huhuanming committed Apr 29, 2024
1 parent 7f8d366 commit db3fce0
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 14 deletions.
152 changes: 152 additions & 0 deletions .github/workflows/release-desktop-snap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: release-desktop-snap

on:
workflow_run:
workflows:
- daily-build
types:
- completed
workflow_dispatch:

jobs:
release-desktop:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]

if: ${{ !github.event.workflow_run || (github.event.workflow_run && github.event.workflow_run.conclusion == 'success') }}
steps:
- name: Checkout Source Code
uses: actions/checkout@v3
with:
lfs: true

- name: Install Snapcraft
uses: samuelmeuli/action-snapcraft@v2

- name: Dotenv Action
id: dotenv
uses: OneKeyHQ/actions/dotenv-action@main
with:
path: .env.version

- name: 'Setup ENV'
run: |
echo "ActionTriggerBy = ${{ github.event.action }} / ${{ github.event_name }}"
# Generate build number ------- start
DATE=`date "+%Y%m%d"`
run_number=$(($workflow_run_number % 100))
run_number=$(printf "%02d" $run_number)
build_number="${DATE}${run_number}"
echo '$build_number='$build_number
echo "BUILD_NUMBER=$build_number" >> $GITHUB_ENV
# Generate build number ------- end
github_ref="${github_ref////-}"
github_ref="${github_ref/refs-heads-/}"
github_ref="${github_ref/refs-tags-/}"
echo '$github_ref='$github_ref
echo "GITHUB_TAG=$github_ref" >> $GITHUB_ENV
# echo "::set-env name=GITHUB_TAG::$github_ref"
eval "$(node -e 'const v=require("./packages/desktop/package.json").version; console.log("pkg_version="+v)')"
echo '$pkg_version='$pkg_version
echo "PKG_VERSION=$pkg_version" >> $GITHUB_ENV
artifacts_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
echo "ARTIFACTS_URL=$artifacts_url" >> $GITHUB_ENV
env:
github_ref: ${{ github.ref }}
workflow_run_number: ${{ github.event.workflow_run.run_number}}

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://npm.pkg.github.com'
always-auth: true
scope: '@onekeyhq'

- name: Setup keys secret
run: |
rm -rf packages/shared/src/analytics/firebase.web.json
echo ${{ secrets.GOOGLE_SERVICE_WEB }} | base64 -d > packages/shared/src/analytics/firebase.web.json
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Dep
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_OPTIONS: '--max_old_space_size=8192'
run: |
yarn
- name: Inject Environment Variables
env:
COVALENT_KEY: ${{ secrets.COVALENT_KEY }}
GITHUB_SHA: ${{ github.sha }}
run: |
echo "COVALENT_KEY=${{ env.COVALENT_KEY }}" >> .env
echo "GITHUB_SHA=${{ env.GITHUB_SHA }}" >> .env
- name: Setup Code Signing file
run: |
echo ${{ secrets.DESKTOP_KEYS_SECRET }} | base64 -d > packages/desktop/sign.p12
- name: Build and Sign Snap Linux
env:
NODE_OPTIONS: '--max_old_space_size=8192'
APPLEID: ${{ secrets.APPLEID }}
APPLEIDPASS: ${{ secrets.APPLEIDPASS }}
ASC_PROVIDER: ${{ secrets.ASC_PROVIDER }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
CSC_LINK: './sign.p12'
run: 'cd apps/desktop && yarn build:snap'

- name: Upload Artifacts Release
uses: actions/upload-artifact@v3
with:
name: release
path: |
./packages/desktop/build-electron/*
!./packages/desktop/build-electron/win-unpacked
!./packages/desktop/build-electron/mac-arm64
!./packages/desktop/build-electron/mac
!./packages/desktop/build-electron/linux-unpacked
!./packages/desktop/build-electron/builder-debug.yml
- name: Upload Artifacts to Snap Linux
if: ${{ github.event.workflow_run }}
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_TOKEN }}
run: |
snapcraft push ./packages/desktop/build-electron/*.snap --release edge
- name: 'Notify to Slack'
uses: onekeyhq/actions/notice-slack-app-update@main
with:
web-hook-url: ${{ secrets.SLACK_DEV_WEBHOOK }}
artifact-type: Desktop
artifact-name: OneKey-Desktop-Linux-Snap-RN
artifact-bundle-id: 'so.onekey.wallet.desktop'
artifact-version-name: '${{ steps.dotenv.outputs.version }}@${{ env.BUILD_NUMBER }}'
artifact-version-code: '${{ env.BUILD_NUMBER }}'
artifact-download-url: '${{ env.ARTIFACTS_URL }}'
change-log: 'Download [Artifacts] at the bottom of page.'
custom-issue-url: ''
custom-message-title: ''
custom-message-payload: ''
10 changes: 0 additions & 10 deletions .github/workflows/release-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ jobs:
with:
lfs: true

- name: Install Snapcraft
uses: samuelmeuli/action-snapcraft@v2

- name: Dotenv Action
id: dotenv
uses: OneKeyHQ/actions/dotenv-action@main
Expand Down Expand Up @@ -162,13 +159,6 @@ jobs:
!./packages/desktop/build-electron/linux-unpacked
!./packages/desktop/build-electron/builder-debug.yml
- name: Upload Artifacts to Snap Linux
if: ${{ github.event.workflow_run }}
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_TOKEN }}
run: |
snapcraft push ./packages/desktop/build-electron/*.snap --release edge
- name: 'Notify to Slack'
uses: onekeyhq/actions/notice-slack-app-update@main
with:
Expand Down
60 changes: 60 additions & 0 deletions packages/desktop/electron-builder-snap.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* eslint-disable no-template-curly-in-string */
require('../../development/env');

module.exports = {
'extraMetadata': {
'main': 'dist/app.js',
'version': process.env.VERSION,
},
'appId': 'so.onekey.wallet.desktop',
'productName': 'OneKey',
'copyright': 'Copyright © ${author}',
'asar': true,
'buildVersion': process.env.BUILD_NUMBER,
'directories': {
'output': 'build-electron',
},
'files': [
'build/**/*',
'!build/static/bin/**/*',
'dist/**/*.js',
'!dist/__**',
'package.json',
],
'protocols': {
'name': 'electron-deep-linking',
'schemes': ['onekey-wallet', 'wc', 'ethereum'],
},
'extraResources': [
{
'from': 'build/static/images/icons/512x512.png',
'to': 'static/images/icons/512x512.png',
},
{
'from': 'build/static/preload.js',
'to': 'static/preload.js',
},
],
'publish': {
'provider': 'github',
'repo': 'app-monorepo',
'owner': 'OneKeyHQ',
},
'snap': {
'grade': 'stable',
},
'linux': {
'extraResources': [
{
'from': 'build/static/bin/bridge/linux-${arch}',
'to': 'bin/bridge',
},
],
'icon': 'build/static/images/icons/512x512.png',
'artifactName': 'OneKey-Wallet-${version}-linux-${arch}.${ext}',
'executableName': 'onekey-wallet',
'category': 'Utility',
'target': ['snap'],
},
'afterSign': 'scripts/notarize.js',
};
5 changes: 1 addition & 4 deletions packages/desktop/electron-builder.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ module.exports = {
'verifyUpdateCodeSignature': false,
'target': ['nsis'],
},
'snap': {
'grade': 'stable',
},
'linux': {
'extraResources': [
{
Expand All @@ -109,7 +106,7 @@ module.exports = {
'artifactName': 'OneKey-Wallet-${version}-linux-${arch}.${ext}',
'executableName': 'onekey-wallet',
'category': 'Utility',
'target': ['AppImage', 'snap'],
'target': ['AppImage'],
},
'afterSign': 'scripts/notarize.js',
};
2 changes: 2 additions & 0 deletions packages/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
"build:renderer": "rm -rf ./build && rm -rf ./web-build && expo export:web && mv ./web-build ./build && rsync -a public/static/ build/static",
"build:main": "rm -rf ./dist && cross-env NODE_ENV=production node scripts/build.js",
"build:electron": "electron-builder build -mwl --config electron-builder.config.js",
"build:electron:snap": "electron-builder build -l --config electron-builder-snap.config.js",
"build:electron:winms": "electron-builder build -w --config electron-builder-ms.config.js",
"build:electron:mac": "electron-builder build -m --config electron-builder.config.js",
"build:electron:mas": "electron-builder build -m --config electron-builder-mas.config.js",
"build": "NODE_ENV=production sh -c \"yarn clean:build && yarn build:renderer && yarn build:main && yarn build:electron --publish never\"",
"build:snap": "NODE_ENV=production && sh -c \"yarn clean:build && yarn build:renderer && yarn build:main && yarn build:electron:snap --publish never\"",
"build:mac": "NODE_ENV=production sh -c \"yarn clean:build && yarn build:renderer && yarn build:main && yarn build:electron:mac --publish never\"",
"build:mas": "NODE_ENV=production sh -c \"yarn clean:build && yarn build:renderer && yarn build:main && yarn build:electron:mas --publish never\"",
"build:winms": "NODE_ENV=production && DESK_CHANNEL=ms-store sh -c \"yarn clean:build && yarn build:renderer && yarn build:main && yarn build:electron:winms --publish never\"",
Expand Down

0 comments on commit db3fce0

Please sign in to comment.