Skip to content

Commit 1d35e1e

Browse files
committed
fix: binary file handling
1 parent aa7e1d2 commit 1d35e1e

File tree

12 files changed

+8906
-2836
lines changed

12 files changed

+8906
-2836
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ jobs:
2525
- name: Setup Node.js
2626
uses: actions/setup-node@v3
2727
with:
28-
node-version: "${{ steps.nvm.outputs.NVMRC }}"
29-
cache: "npm"
28+
node-version: ${{ steps.nvm.outputs.NVMRC }}
29+
cache: npm
3030

3131
- name: Update npm
3232
run: npm install -g npm@latest
@@ -44,7 +44,7 @@ jobs:
4444
INPUT_TOKEN: ${{ secrets.TOKEN }}
4545
run: npm run all
4646

47-
action-with-all-inputs:
47+
with-all-inputs:
4848
runs-on: ubuntu-latest
4949
steps:
5050
- uses: actions/checkout@v3
@@ -57,8 +57,9 @@ jobs:
5757
gist_description: "foo bar"
5858
gist_file_name: foo.bar
5959
file_path: ./__tests__/foo.bar
60+
file_type: text
6061

61-
action-with-minimum-inputs:
62+
with-minimum-inputs:
6263
runs-on: ubuntu-latest
6364
steps:
6465
- uses: actions/checkout@v3
@@ -69,3 +70,16 @@ jobs:
6970
token: ${{ secrets.TOKEN }}
7071
gist_id: e885afa349a0e5d1cfb408e46d6a37bc
7172
file_path: ./__tests__/foo.bar
73+
74+
with-binary-file:
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v3
78+
79+
- name: Test action
80+
uses: ./
81+
with:
82+
token: ${{ secrets.TOKEN }}
83+
gist_id: e885afa349a0e5d1cfb408e46d6a37bc
84+
file_path: ./__tests__/dummy.pdf
85+
file_type: binary

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,7 @@ Thumbs.db
9696

9797
# Ignore built ts files
9898
__tests__/runner/*
99-
lib/**/*
99+
lib/**/*
100+
101+
# Tests
102+
tmp

__tests__/dummy.pdf

13 KB
Binary file not shown.

__tests__/index.test.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { execSync } from 'child_process'
2-
import path from 'path'
2+
import { join } from 'path'
33
import dotenv from 'dotenv'
44
import { getInput } from '../src/input'
55

@@ -23,13 +23,33 @@ test('input', () => {
2323
})
2424

2525
test('run', () => {
26-
process.env.GITHUB_WORKSPACE = process.cwd()
26+
const cwd = process.cwd()
27+
28+
process.env.RUNNER_TEMP = join(cwd, 'tmp')
29+
process.env.GITHUB_WORKSPACE = cwd
30+
2731
process.env.INPUT_GIST_ID = 'e885afa349a0e5d1cfb408e46d6a37bc'
2832
process.env.INPUT_GIST_DESCRIPTION = 'foo bar'
33+
34+
const run = (): void => {
35+
try {
36+
const stdout = execSync(`node ${join(__dirname, '../lib/index.js')}`, {
37+
env: process.env,
38+
encoding: 'utf8'
39+
})
40+
console.log(stdout)
41+
} catch (err) {
42+
console.error(err)
43+
expect(err).toBeFalsy()
44+
}
45+
}
46+
2947
process.env.INPUT_GIST_FILE_NAME = 'foo.bar'
3048
process.env.INPUT_FILE_PATH = '__tests__/foo.bar'
49+
run()
3150

32-
const filePath = path.join(__dirname, '../lib/index.js')
33-
const stdoutBuffer = execSync(`node ${filePath}`, { env: process.env })
34-
console.log(stdoutBuffer.toString())
51+
process.env.INPUT_GIST_FILE_NAME = 'dummy.pdf'
52+
process.env.INPUT_FILE_PATH = '__tests__/dummy.pdf'
53+
process.env.INPUT_FILE_TYPE = 'binary'
54+
run()
3555
})

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ inputs:
2020
file_path:
2121
required: true
2222
description: "Set path of the file to be deployed."
23+
file_type:
24+
required: false
25+
description: "Set file type of the file to be deployed."
26+
default: "text"
2327
runs:
2428
using: "node16"
2529
main: "dist/index.js"

0 commit comments

Comments
 (0)