Merge branch 'test/action' into dev

This commit is contained in:
Lucas Nogueira
2020-07-08 00:13:49 -03:00
9 changed files with 86 additions and 54 deletions

70
.github/workflows/test-action.yml vendored Normal file
View File

@@ -0,0 +1,70 @@
name: "test-action"
on:
push:
branches: [dev]
jobs:
create-release:
runs-on: ubuntu-latest
outputs:
RELEASE_UPLOAD_ID: ${{ steps.create_tauri_release.outputs.upload_id }}
steps:
- uses: actions/checkout@v2
- name: setup node
uses: actions/setup-node@v1
with:
node-version: 12
- name: get version
run: echo ::set-env name=PACKAGE_VERSION::$(node -p "require('./package.json').version")
working-directory: ./example
- name: create release
id: create_tauri_release
uses: jbolda/create-release@v1.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: example-v${{ env.PACKAGE_VERSION }}
release_name: "Release example app v${{ env.PACKAGE_VERSION }}"
body: "See the assets to download this version and install."
draft: true
prerelease: false
build:
needs: create-release
strategy:
fail-fast: false
matrix:
platform: [macos-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- name: setup node
uses: actions/setup-node@v1
with:
node-version: 12
- name: install Rust stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: install tauri bundler
run: cargo install tauri-bundler --force
- name: install webkit2gtk (ubuntu only)
if: matrix.platform == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y webkit2gtk-4.0
- name: build action
run: |
yarn
yarn build
- name: install example dependencies
run: yarn
working-directory: ./example
- uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
projectPath: ./example
releaseId: ${{ needs.create-release.outputs.RELEASE_UPLOAD_ID }}

View File

@@ -1,23 +0,0 @@
name: "build-test"
on: # rebuild any PRs and main branch changes
pull_request:
push:
branches:
- master
- 'releases/*'
jobs:
build: # make sure build/ci work properly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: |
npm install
npm run all
test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: ./
with:
milliseconds: 1000

View File

@@ -18,7 +18,7 @@ jobs:
create-release:
runs-on: ubuntu-latest
outputs:
RELEASE_UPLOAD_URL: ${{ steps.create_tauri_release.outputs.upload_url }}
RELEASE_UPLOAD_ID: ${{ steps.create_tauri_release.outputs.upload_id }}
steps:
- uses: actions/checkout@v2
@@ -75,7 +75,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
uploadUrl: ${{ needs.create-release.outputs.RELEASE_UPLOAD_URL }}
releaseId: ${{ needs.create-release.outputs.RELEASE_UPLOAD_ID }}
```
## Inputs

View File

@@ -3,9 +3,7 @@ description: 'Provide a description here'
author: 'Lucas Nogueira <lucas@tauri.studio>'
inputs:
releaseId:
description: 'The id of the release to upload the assets'
uploadUrl:
description: 'The URL for uploading assets to the release'
description: 'The id of the release to upload assets'
projectPath:
description: 'path to the root of the project that will be built'
default: '.'

13
dist/main.js vendored
View File

@@ -118,24 +118,19 @@ function buildProject(root, debug, { configPath, distPath }) {
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const projectPath = core.getInput('projectPath') || process.argv[2];
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 uploadUrl = core.getInput('uploadUrl');
const releaseId = core.getInput('releaseId');
if ((!!uploadUrl) !== (!!releaseId)) {
core.setFailed('To upload artifacts to a release, you need to set both `releaseId` and `uploadUrl`.');
return;
}
const artifacts = yield buildProject(projectPath, false, { configPath: fs_1.existsSync(configPath) ? configPath : null, distPath });
if (uploadUrl && releaseId) {
if (releaseId) {
if (os_1.platform() === 'darwin') {
let index = -1;
let i = 0;
for (const artifact of artifacts) {
if (artifact.endsWith('.app')) {
index = i;
yield execCommand(`tar -czf ${artifact}`, { cwd: projectPath });
yield execCommand(`tar -czf ${artifact}.tgz ${artifact}`, { cwd: undefined });
}
i++;
}
@@ -143,7 +138,7 @@ function run() {
artifacts[index] = artifacts[index] + '.tgz';
}
}
yield upload_release_assets_1.default(uploadUrl, Number(releaseId), artifacts);
yield upload_release_assets_1.default(Number(releaseId), artifacts);
}
}
catch (error) {

View File

@@ -35,7 +35,7 @@ const core = __importStar(require("@actions/core"));
const github_1 = require("@actions/github");
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
function uploadAssets(uploadUrl, releaseId, assets) {
function uploadAssets(releaseId, assets) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (process.env.GITHUB_TOKEN === undefined) {
@@ -47,13 +47,12 @@ function uploadAssets(uploadUrl, releaseId, assets) {
for (const assetPath of assets) {
const headers = { 'content-type': 'application/zip', 'content-length': contentLength(assetPath) };
yield github.repos.uploadReleaseAsset({
url: uploadUrl,
release_id: releaseId,
headers,
name: path_1.default.basename(assetPath),
data: fs_1.default.readFileSync(assetPath).toString(),
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
release_id: Number(releaseId)
owner: github_1.context.repo.owner
});
}
}

View File

@@ -43,4 +43,4 @@
"ts-jest": "^24.2.0",
"typescript": "^3.6.4"
}
}
}

View File

@@ -91,17 +91,11 @@ async function run(): Promise<void> {
const projectPath = resolve(process.cwd(), core.getInput('projectPath') || process.argv[2])
const configPath = join(projectPath, core.getInput('configPath') || 'tauri.conf.json')
const distPath = core.getInput('distPath')
const uploadUrl = core.getInput('uploadUrl')
const releaseId = core.getInput('releaseId')
if ((!!uploadUrl) !== (!!releaseId)) {
core.setFailed('To upload artifacts to a release, you need to set both `releaseId` and `uploadUrl`.')
return
}
const artifacts = await buildProject(projectPath, false, { configPath: existsSync(configPath) ? configPath : null, distPath })
if (uploadUrl && releaseId) {
if (releaseId) {
if (platform() === 'darwin') {
let index = -1
let i = 0
@@ -116,7 +110,7 @@ async function run(): Promise<void> {
artifacts[index] = artifacts[index] + '.tgz'
}
}
await uploadReleaseAssets(uploadUrl, Number(releaseId), artifacts)
await uploadReleaseAssets(Number(releaseId), artifacts)
}
} catch (error) {
core.setFailed(error.message)

View File

@@ -3,7 +3,7 @@ import { getOctokit, context } from '@actions/github'
import fs from 'fs'
import path from 'path'
export default async function uploadAssets(uploadUrl: string, releaseId: number, assets: string[]) {
export default async function uploadAssets(releaseId: number, assets: string[]) {
try {
if (process.env.GITHUB_TOKEN === undefined) {
throw new Error('GITHUB_TOKEN is required')
@@ -18,13 +18,12 @@ export default async function uploadAssets(uploadUrl: string, releaseId: number,
const headers = { 'content-type': 'application/zip', 'content-length': contentLength(assetPath) }
await github.repos.uploadReleaseAsset({
url: uploadUrl,
release_id: releaseId,
headers,
name: path.basename(assetPath),
data: fs.readFileSync(assetPath).toString(),
owner: context.repo.owner,
repo: context.repo.repo,
release_id: Number(releaseId)
owner: context.repo.owner
})
}
} catch (error) {