Skip to content

Commit

Permalink
Smarter release workflow (#1525)
Browse files Browse the repository at this point in the history
* js-based publish workflow

* don't create release if not using tag

* rename

* update lockfile

* remove unnecessary tsconfigs

* replace old publish action

* dumb

* esmodule moment

* glob files

* lockfile

* build app bundle

* Fix artifact upload hopefully

* upload artifacts from root

* skill issue ffs

* Use copy instead of move

* hopefully last one

* artifcats

* make .artifacts -_-

* ffs

* Make cp recursive, so it work with dirs

* build

* separate updater & standalone targets

* create draft release

---------

Co-authored-by: Vítor Vasconcellos <[email protected]>
  • Loading branch information
Brendonovich and HeavenVolkoff committed Oct 13, 2023
1 parent 39744b5 commit b27c5ac
Show file tree
Hide file tree
Showing 9 changed files with 364 additions and 59 deletions.
1 change: 1 addition & 0 deletions .github/actions/publish-artifacts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!dist
60 changes: 6 additions & 54 deletions .github/actions/publish-artifacts/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,10 @@ inputs:
description: target triples for built artifact
profile:
description: "'debug' or 'release'"
os:
description: "'darwin', 'windows', or 'linux'"
arch:
description: "'x86_64' or 'aarch64'"
runs:
using: 'composite'
steps:
- name: Determine short GitHub SHA
shell: bash
run: |
export GITHUB_SHA_SHORT=$(git rev-parse --short "$GITHUB_SHA")
echo "GITHUB_SHA_SHORT=$GITHUB_SHA_SHORT" >> $GITHUB_ENV
- name: Publish artifacts (Linux - AppImage)
if: ${{ matrix.settings.host == 'ubuntu-20.04' }}
uses: actions/upload-artifact@v3
with:
name: Spacedrive-AppImage-${{ inputs.target }}-${{ env.GITHUB_SHA_SHORT }}
path: target/${{ inputs.target }}/${{ inputs.profile }}/bundle/appimage/*.AppImage
if-no-files-found: error
retention-days: 1

- name: Publish artifacts (Debian - deb)
if: ${{ matrix.settings.host == 'ubuntu-20.04' }}
uses: actions/upload-artifact@v3
with:
name: Spacedrive-deb-${{ inputs.target }}-${{ env.GITHUB_SHA_SHORT }}
path: target/${{ inputs.target }}/${{ inputs.profile }}/bundle/deb/*.deb
if-no-files-found: error
retention-days: 1

- name: Publish artifacts (Windows - msi)
if: ${{ matrix.settings.host == 'windows-latest' }}
uses: actions/upload-artifact@v3
with:
name: Spacedrive-Windows-msi-${{ inputs.target }}-${{ env.GITHUB_SHA_SHORT }}
path: target/${{ inputs.target }}/${{ inputs.profile }}/bundle/msi/*.msi
if-no-files-found: error
retention-days: 1

- name: Publish artifacts (macOS - dmg)
if: ${{ matrix.settings.host == 'macos-latest' }}
uses: actions/upload-artifact@v3
with:
name: Spacedrive-macOS-dmg-${{ inputs.target }}-${{ env.GITHUB_SHA_SHORT }}
path: target/${{ inputs.target }}/${{ inputs.profile }}/bundle/dmg/*.dmg
if-no-files-found: error
retention-days: 1

- name: Publish updater binaries
uses: actions/upload-artifact@v3
with:
name: Spacedrive-Updater-${{ inputs.target }}-${{ env.GITHUB_SHA_SHORT }}
path: |
target/${{ inputs.target }}/${{ inputs.profile }}/bundle/**/*.tar.gz*
target/${{ inputs.target }}/${{ inputs.profile }}/bundle/**/*.zip*
!target/**/deb/**/*.tar.gz
if-no-files-found: error
retention-days: 1
using: node20
main: dist/index.js
11 changes: 11 additions & 0 deletions .github/actions/publish-artifacts/dist/index.js

Large diffs are not rendered by default.

102 changes: 102 additions & 0 deletions .github/actions/publish-artifacts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import * as artifact from '@actions/artifact';
import * as core from '@actions/core';
import * as glob from '@actions/glob';
import * as io from '@actions/io';

type OS = 'darwin' | 'windows' | 'linux';
type Arch = 'x64' | 'arm64';
type TargetConfig = { bundle: string; ext: string };
type BuildTarget = {
updater: TargetConfig;
standalone: Array<TargetConfig>;
};

const OS_TARGETS = {
darwin: {
updater: {
bundle: 'macos',
ext: 'app.tar.gz'
},
standalone: [{ ext: 'dmg', bundle: 'dmg' }]
},
windows: {
updater: {
bundle: 'msi',
ext: 'msi.zip'
},
standalone: [{ ext: 'msi', bundle: 'msi' }]
},
linux: {
updater: {
bundle: 'appimage',
ext: 'AppImage.tar.gz'
},
standalone: [
{ ext: 'deb', bundle: 'deb' },
{ ext: 'AppImage', bundle: 'appimage' }
]
}
} satisfies Record<OS, BuildTarget>;

// Workflow inputs
const OS: OS = core.getInput('os') as any;
const ARCH: Arch = core.getInput('arch') as any;
const TARGET = core.getInput('target');
const PROFILE = core.getInput('profile');

const BUNDLE_DIR = `target/${TARGET}/${PROFILE}/bundle`;
const ARTIFACTS_DIR = '.artifacts';
const ARTIFACT_BASE = `Spacedrive-${OS}-${ARCH}`;
const UPDATER_ARTIFACT_NAME = `Spacedrive-Updater-${OS}-${ARCH}`;

const client = artifact.create();

async function globFiles(pattern: string) {
const globber = await glob.create(pattern);
return await globber.glob();
}

async function uploadUpdater({ bundle, ext }: TargetConfig) {
const files = await globFiles(`${BUNDLE_DIR}/${bundle}/*.${ext}*`);

const updaterPath = files.find((file) => file.endsWith(ext));
if (!updaterPath) return console.error(`Updater path not found. Files: ${files}`);

const artifactPath = `${ARTIFACTS_DIR}/${UPDATER_ARTIFACT_NAME}.${ext}`;

// https://tauri.app/v1/guides/distribution/updater#update-artifacts
await io.cp(updaterPath, artifactPath);
await io.cp(`${updaterPath}.sig`, `${artifactPath}.sig`);

await client.uploadArtifact(
UPDATER_ARTIFACT_NAME,
[artifactPath, `${artifactPath}.sig`],
ARTIFACTS_DIR
);
}

async function uploadStandalone({ bundle, ext }: TargetConfig) {
const files = await globFiles(`${BUNDLE_DIR}/${bundle}/*.${ext}*`);

const standalonePath = files.find((file) => file.endsWith(ext));
if (!standalonePath) return console.error(`Standalone path not found. Files: ${files}`);

const artifactName = `${ARTIFACT_BASE}.${ext}`;
const artifactPath = `${ARTIFACTS_DIR}/${artifactName}`;

await io.cp(standalonePath, artifactPath, { recursive: true });
await client.uploadArtifact(artifactName, [artifactPath], ARTIFACTS_DIR);
}

async function run() {
await io.mkdirP(ARTIFACTS_DIR);

const { updater, standalone } = OS_TARGETS[OS];

await uploadUpdater(updater);

for (const config of standalone) {
await uploadStandalone(config);
}
}
run();
16 changes: 16 additions & 0 deletions .github/actions/publish-artifacts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"private": true,
"scripts": {
"build": "ncc build index.ts --minify"
},
"dependencies": {
"@actions/artifact": "^1.1.2",
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@actions/glob": "^0.4.0",
"@actions/io": "^1.1.3"
},
"devDependencies": {
"@vercel/ncc": "^0.38.0"
}
}
11 changes: 11 additions & 0 deletions .github/actions/publish-artifacts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es2015" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"module": "esnext" /* Specify what module code is generated. */,
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
"strict": true /* Enable all strict type-checking options. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
35 changes: 30 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,35 @@ name: Release

on:
workflow_dispatch:

# NOTE: For Linux builds, we can only build with Ubuntu. It should be the oldest base system we intend to support. See PR-759 & https://tauri.app/v1/guides/building/linux for reference.

jobs:
desktop-main:
strategy:
fail-fast: true
matrix:
settings:
- host: macos-latest
target: x86_64-apple-darwin
bundles: dmg
bundles: app,dmg
os: darwin
arch: x86_64
- host: macos-latest
target: aarch64-apple-darwin
bundles: dmg
bundles: app,dmg
os: darwin
arch: aarch64
- host: windows-latest
target: x86_64-pc-windows-msvc
bundles: msi
os: windows
arch: x86_64
# - host: windows-latest
# target: aarch64-pc-windows-msvc
- host: ubuntu-20.04
target: x86_64-unknown-linux-gnu
bundles: appimage,deb
bundles: deb,appimage
os: linux
arch: x86_64
# - host: ubuntu-20.04
# target: x86_64-unknown-linux-musl
# - host: ubuntu-20.04
Expand Down Expand Up @@ -112,5 +118,24 @@ jobs:
- name: Publish Artifacts
uses: ./.github/actions/publish-artifacts
with:
os: ${{ matrix.settings.os }}
arch: ${{ matrix.settings.arch }}
target: ${{ matrix.settings.target }}
profile: release

release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
name: Create Release
needs: desktop-main
permissions:
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v3

- name: Create Release
uses: softprops/action-gh-release@v1
with:
draft: true
files: "*/**"
Loading

1 comment on commit b27c5ac

@vercel
Copy link

@vercel vercel bot commented on b27c5ac Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.