fix(action): test CI and fixes for usage with tauri beta-rc (#114)

Co-authored-by: David Lemarier <david@lemarier.ca>
This commit is contained in:
Lucas Fernandes Nogueira
2021-04-28 13:18:46 -03:00
committed by GitHub
parent b874256141
commit dbbc6b4e60
48 changed files with 226 additions and 4434 deletions

View File

@@ -3,23 +3,54 @@
"pkgManagers": {
"javascript": {
"version": true,
"build": false,
"preversion": "yarn pkg",
"publish": false,
"getPublishedVersion": false,
"assets": false
"getPublishedVersion": "npm view ${ pkg.pkg } version",
"prepublish": [
{
"command": "npm pack",
"dryRunCommand": true
}
],
"publish": [
{
"command": "echo # Package Publish",
"dryRunCommand": "echo # Package Publish",
"pipe": true
},
{
"command": "npm publish --access public",
"dryRunCommand": "echo publish here",
"pipe": true
}
]
}
},
"packages": {
"core": {
"path": "./packages/core",
"manager": "javascript"
},
"action": {
"path": "./packages/action",
"manager": "javascript",
"postpublish": [
"git tag ${ pkg.pkg }-v${ pkgFile.versionMajor } -f",
"git tag ${ pkg.pkg }-v${ pkgFile.versionMajor }.${ pkgFile.versionMinor } -f",
"git push --tags -f"
],
"dependencies": [
"core"
],
"assets": [
{
"path": "./packages/action/tauri-action-${ pkgFile.version }.tgz",
"name": "tauri-action-${ pkgFile.version }.tgz"
}
]
},
"core": {
"path": "./packages/core",
"manager": "javascript",
"assets": [
{
"path": "./packages/core/tauri-apps-action-core-${ pkgFile.version }.tgz",
"name": "action-core-${ pkgFile.version }.tgz"
}
]
}
}

View File

@@ -1,5 +1,6 @@
---
"action": minor
"core": minor
---
Update to Tauri beta release candidate.

View File

@@ -15,7 +15,7 @@ jobs:
- name: setup node
uses: actions/setup-node@v1
with:
node-version: 12
node-version: 14
- name: install Rust stable
uses: actions-rs/toolchain@v1
with:
@@ -28,26 +28,26 @@ jobs:
- name: build action
run: |
yarn
yarn build
yarn workspaces run build
- name: install example dependencies
run: yarn
working-directory: ./__fixtures__/example
- uses: ./
working-directory: ./packages/action/__fixtures__/example
- uses: ./packages/action
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
projectPath: ./__fixtures__/example
projectPath: ./packages/action/__fixtures__/example
iconPath: ./icon.png
tagName: example-v__VERSION__
releaseName: "Release example app v__VERSION__"
releaseBody: "See the assets to download this version and install."
releaseDraft: true
prerelease: false
- uses: ./
- uses: ./packages/action
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
projectPath: ./__fixtures__/example-with-tauri
projectPath: ./packages/action/__fixtures__/example-with-tauri
tagName: example-with-tauri-v__VERSION__
releaseName: "Release example with preconfigured Tauri app v__VERSION__"
releaseBody: "See the assets to download this version and install."

1
.gitignore vendored
View File

@@ -48,3 +48,4 @@ dist
# but we want the action dist
!packages/action/dist
!packages/action/dist/**
!packages/action/__fixtures__/**/dist

View File

@@ -1,8 +0,0 @@
<!DOCTYPE html>
<html>
<body>
<div>Test Application with Tauri configured</div>
</body>
</html>

View File

@@ -1,8 +0,0 @@
<!DOCTYPE html>
<html>
<body>
<div>Test Application</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head></head>
<body>
<h3>Hello!</h3>
</body>
</html>

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 56 KiB

View File

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 88 KiB

View File

@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head></head>
<body>
<h3>Hello!</h3>
</body>
</html>

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -1,53 +1,17 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const tslib_1 = require("tslib");
const core = tslib_1.__importStar(require("@actions/core"));
const github_1 = require("@actions/github");
const fs_1 = __importDefault(require("fs"));
const fs_1 = tslib_1.__importDefault(require("fs"));
function allReleases(github) {
const params = Object.assign({ per_page: 100 }, github_1.context.repo);
return github.paginate.iterator(github.repos.listReleases.endpoint.merge(params));
}
function createRelease(tagName, releaseName, body, commitish, draft = true, prerelease = true) {
var e_1, _a;
return __awaiter(this, void 0, void 0, function* () {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (process.env.GITHUB_TOKEN === undefined) {
throw new Error('GITHUB_TOKEN is required');
}
@@ -72,7 +36,7 @@ function createRelease(tagName, releaseName, body, commitish, draft = true, prer
if (draft) {
console.log(`Looking for a draft release with tag ${tagName}...`);
try {
for (var _b = __asyncValues(allReleases(github)), _c; _c = yield _b.next(), !_c.done;) {
for (var _b = tslib_1.__asyncValues(allReleases(github)), _c; _c = yield _b.next(), !_c.done;) {
const response = _c.value;
let releaseWithTag = response.data.find(release => release.tag_name === tagName);
if (releaseWithTag) {

View File

@@ -1,5 +1,91 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const src_1 = require("./src");
src_1.run();
const tslib_1 = require("tslib");
const os_1 = require("os");
const core = tslib_1.__importStar(require("@actions/core"));
const path_1 = require("path");
const fs_1 = require("fs");
const upload_release_assets_1 = tslib_1.__importDefault(require("./upload-release-assets"));
const create_release_1 = tslib_1.__importDefault(require("./create-release"));
const action_core_1 = require("@tauri-apps/action-core");
function run() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const preferGlobal = core.getInput('preferGlobal') === 'true';
const projectPath = path_1.resolve(process.cwd(), core.getInput('projectPath') || process.argv[2]);
const configPath = path_1.join(projectPath, core.getInput('configPath') || 'tauri.conf.json');
const distPath = core.getInput('distPath');
const iconPath = core.getInput('iconPath');
const includeDebug = core.getInput('includeDebug') === 'true';
const npmScript = core.getInput('npmScript');
let tagName = core.getInput('tagName').replace('refs/tags/', '');
let releaseName = core.getInput('releaseName').replace('refs/tags/', '');
let body = core.getInput('releaseBody');
const draft = core.getInput('releaseDraft') === 'true';
const prerelease = core.getInput('prerelease') === 'true';
const commitish = core.getInput('releaseCommitish') || null;
if (Boolean(tagName) !== Boolean(releaseName)) {
throw new Error('`tag` is required along with `releaseName` when creating a release.');
}
const options = {
configPath: fs_1.existsSync(configPath) ? configPath : null,
distPath,
iconPath,
npmScript
};
const artifacts = yield action_core_1.buildProject(preferGlobal, projectPath, false, options);
if (includeDebug) {
const debugArtifacts = yield action_core_1.buildProject(preferGlobal, projectPath, true, options);
artifacts.push(...debugArtifacts);
}
if (artifacts.length === 0) {
throw new Error('No artifacts were found.');
}
console.log(`Artifacts: ${artifacts}.`);
let releaseId;
if (tagName) {
const packageJson = action_core_1.getPackageJson(projectPath);
const templates = [
{
key: '__VERSION__',
value: packageJson === null || packageJson === void 0 ? void 0 : packageJson.version
}
];
templates.forEach(template => {
const regex = new RegExp(template.key, 'g');
tagName = tagName.replace(regex, template.value);
releaseName = releaseName.replace(regex, template.value);
body = body.replace(regex, template.value);
});
const releaseData = yield create_release_1.default(tagName, releaseName, body, commitish || undefined, draft, prerelease);
releaseId = releaseData.id;
core.setOutput('releaseUploadUrl', releaseData.uploadUrl);
core.setOutput('releaseId', releaseData.id.toString());
core.setOutput('releaseHtmlUrl', releaseData.htmlUrl);
}
else {
releaseId = Number(core.getInput('releaseId') || 0);
}
if (releaseId) {
if (os_1.platform() === 'darwin') {
let i = 0;
for (const artifact of artifacts) {
if (artifact.endsWith('.app')) {
yield action_core_1.execCommand(`tar -czf ${artifact}.tgz ${artifact}`, {
cwd: undefined
});
artifacts[i] += '.tgz';
}
i++;
}
}
yield upload_release_assets_1.default(releaseId, artifacts);
}
}
catch (error) {
core.setFailed(error.message);
}
});
}
run();

View File

@@ -1,22 +1,12 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const github_1 = require("@actions/github");
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const fs_1 = tslib_1.__importDefault(require("fs"));
const path_1 = tslib_1.__importDefault(require("path"));
function uploadAssets(releaseId, assets) {
return __awaiter(this, void 0, void 0, function* () {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (process.env.GITHUB_TOKEN === undefined) {
throw new Error('GITHUB_TOKEN is required');
}

View File

@@ -1,4 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const src_1 = require("./src");
src_1.run();

View File

@@ -1,2 +0,0 @@
import { run } from './src'
run()

View File

@@ -4,7 +4,11 @@ import pkg from "./package.json";
export default {
treeshake: true,
perf: true,
input: { index: "index.ts" },
input: {
index: "src/index.ts",
"create-release": "src/create-release.ts",
"upload-release-assets": "src/upload-release-assets.ts"
},
output: {
dir: "dist",
format: "cjs",

View File

@@ -7,7 +7,7 @@ import createRelease from './create-release'
import { getPackageJson, buildProject, execCommand } from '@tauri-apps/action-core'
import type { BuildOptions } from '@tauri-apps/action-core'
export async function run(): Promise<void> {
async function run(): Promise<void> {
try {
const preferGlobal = core.getInput('preferGlobal') === 'true'
const projectPath = resolve(
@@ -106,3 +106,5 @@ export async function run(): Promise<void> {
core.setFailed(error.message)
}
}
run()

View File

@@ -36,8 +36,6 @@ export function execCommand(
const [cmd, ...args] = command.split(' ')
return execa(cmd, args, {
cwd,
shell: process.env.shell || true,
windowsHide: true,
stdio: 'inherit',
env: { FORCE_COLOR: '0' }
}).then()
@@ -52,6 +50,13 @@ interface CargoManifest {
bin: CargoManifestBin[]
}
interface TauriConfig {
package?: {
productName?: string
version?: string
}
}
interface Application {
runner: string
name: string
@@ -81,21 +86,41 @@ export async function buildProject(
resolve(usesYarn(root) ? 'yarn tauri' : 'npx tauri')
}
} else {
execCommand('npm install -g @tauri-apps/cli', { cwd: undefined }).then(() =>
execCommand('npm install -g @tauri-apps/cli', { cwd: undefined }).then(() => {
resolve('tauri')
).catch(reject)
}).catch(reject)
}
})
.then((runner: string) => {
const manifestPath = join(root, 'src-tauri/Cargo.toml')
if (existsSync(manifestPath)) {
const cargoManifest = (toml.parse(
readFileSync(manifestPath).toString()
) as any) as CargoManifest
const configPath = join(root, 'src-tauri/tauri.conf.json')
if (existsSync(configPath)) {
let name
let version
const config = JSON.parse(
readFileSync(configPath).toString()
) as TauriConfig
if (config.package) {
name = config.package.productName
version = config.package.version
}
if (!(name || version)) {
const manifestPath = join(root, 'src-tauri/Cargo.toml')
const cargoManifest = (toml.parse(
readFileSync(manifestPath).toString()
) as any) as CargoManifest
name = name || cargoManifest.package.name
version = version || cargoManifest.package.version
}
if (!(name || version)) {
console.error('Could not determine package name and version')
process.exit(1)
}
return {
runner,
name: cargoManifest.package.name,
version: cargoManifest.package.version
name,
version
}
} else {
const packageJson = getPackageJson(root)
@@ -105,16 +130,26 @@ export async function buildProject(
return execCommand(`${runner} init --ci --app-name ${appName}`, {
cwd: root
}).then(() => {
const cargoManifest = (toml.parse(
readFileSync(manifestPath).toString()
) as any) as CargoManifest
const config = JSON.parse(
readFileSync(configPath).toString()
) as TauriConfig
const version = packageJson ? packageJson.version : '0.1.0'
console.log(
`Replacing cargo manifest options - package.version=${version}`
`Replacing tauri.conf.json config - package.version=${version}`
)
cargoManifest.package.version = version
writeFileSync(manifestPath, toml.stringify(cargoManifest as any))
const pkgConfig = {
...config.package,
version
}
if (packageJson?.productName) {
console.log(
`Replacing tauri.conf.json config - package.productName=${packageJson.productName}`
)
pkgConfig.productName = packageJson.productName
}
config.package = pkgConfig
writeFileSync(configPath, JSON.stringify(config, null, 2))
const app = {
runner,
@@ -122,7 +157,7 @@ export async function buildProject(
version
}
if (iconPath) {
return execCommand(`${runner} icon --i ${join(root, iconPath)}`, {
return execCommand(`${runner} icon ${join(root, iconPath)}`, {
cwd: root
}).then(() => app)
}

View File

@@ -10,10 +10,5 @@
"moduleResolution": "node",
"importHelpers": true
},
"baseUrl": ".",
"exclude": [
"__fixtures__",
"**/dist/**",
"**/bin/**"
]
"baseUrl": "."
}