Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upload app with is-latest option #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Integrate github action with Dogu

- `project-id`
- `file-path`
- `is-latest`

# Env

Expand All @@ -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 }}
```
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down