From 81e0b4102d719566f82a44ccf7cb98b65675e891 Mon Sep 17 00:00:00 2001 From: Daniel Ahn Date: Tue, 12 Sep 2023 17:09:02 +0900 Subject: [PATCH] feat: upload app with is-latest option --- README.md | 2 ++ action.yml | 3 +++ src/api.ts | 4 ++-- src/template.ts | 3 ++- test/test.ts | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4254410..c997894 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Integrate github action with Dogu - `project-id` - `file-path` +- `is-latest` # Env @@ -48,6 +49,7 @@ Integrate github action with Dogu template: upload_application project-id: 'a5792d9b-a8e8-4ab8-b790-3a503c5a8789' file-path: '/usr/project/build/app.apk' + is-latest: true env: DOGU_TOKEN: ${{ secrets.DOGU_TOKEN }} ``` diff --git a/action.yml b/action.yml index f27b91e..1ad5515 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,9 @@ inputs: api-url: required: false description: 'API URL' + is-latest: + required: false + description: 'Upload app as latest' timeout: require: false description: 'Timeout ms' diff --git a/src/api.ts b/src/api.ts index a24000c..e83de61 100644 --- a/src/api.ts +++ b/src/api.ts @@ -2,7 +2,6 @@ import axios from 'axios'; import WebSocket from 'ws'; import * as core from '@actions/core'; import FormData from 'form-data'; -import fs from "fs/promises" import { PipelieState } from './types'; import { DoguOption } from './option'; @@ -91,11 +90,12 @@ export module API { }); } - export async function uploadApplication(projectId: string, application: Buffer, applicationName: string) { + export async function uploadApplication(projectId: string, application: Buffer, applicationName: string, isLatest: boolean) { const form = new FormData(); form.append('file', application, { 'filename': applicationName, }); + form.append('isLatest', isLatest.toString()); const response = await axios.put(`${DoguOption.API_URL}/v1/projects/${projectId}/applications`, form, { headers: { diff --git a/src/template.ts b/src/template.ts index 8e82fc2..4476e00 100644 --- a/src/template.ts +++ b/src/template.ts @@ -31,11 +31,12 @@ export const Template = { 'upload_application': async () => { const projectId = core.getInput('project-id'); const filePath = core.getInput('file-path'); + const isLatest = core.getInput('is-latest'); try { const application = await fs.readFile(filePath); const applicationName = path.basename(filePath); - const response = await API.uploadApplication(projectId, application, applicationName); + const response = await API.uploadApplication(projectId, application, applicationName, isLatest === 'true'); } catch (error: any) { if (error.response) { diff --git a/test/test.ts b/test/test.ts index 95a74b1..a4f6da3 100644 --- a/test/test.ts +++ b/test/test.ts @@ -15,7 +15,7 @@ import path from 'path'; const application = await fs.readFile(filePath); const applicationName = path.basename(filePath); try { - await API.uploadApplication(projectId, application, applicationName) + await API.uploadApplication(projectId, application, applicationName, true); } catch (error: any) { console.log(error.response.data.message)