Skip to content

Commit

Permalink
feat: publish-target #6 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidp94 authored Nov 25, 2021
1 parent 2a98fba commit c0debce
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,39 @@ jobs:
refresh-token: ${{ secrets.REFRESH_TOKEN }}
publish: false
```


Example with `publish-target` for publishing to `trustedTesters`:

```yaml
name: Test
on:
push:
tags:
- '*'
jobs:
build:
name: Publish webextension
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
- name: Build
run: |
npm ci
npm run build
- name: Upload & release
uses: mnao305/chrome-extension-upload@2.1.0
with:
file-path: dist/file.zip
extension-id: hogefuga(extension id)
client-id: ${{ secrets.CLIENT_ID }}
refresh-token: ${{ secrets.REFRESH_TOKEN }}
publish-target: trustedTesters
```
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ inputs:
publish:
description: 'if true package will be automatically published'
default: true
publish-target:
required: false
description: 'target of publish (`default` or `trustedTesters`)'
default: "default"
runs:
using: 'node12'
main: 'dist/index.js'
9 changes: 5 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3753,7 +3753,7 @@ const core = __importStar(__webpack_require__(470));
const fs_1 = __importDefault(__webpack_require__(747));
const glob_1 = __importDefault(__webpack_require__(402));
const chrome_webstore_upload_1 = __importDefault(__webpack_require__(673));
function uploadFile(webStore, filePath, publishFlg) {
function uploadFile(webStore, filePath, publishFlg, publishTarget) {
const myZipFile = fs_1.default.createReadStream(filePath);
webStore
.uploadExisting(myZipFile)
Expand All @@ -3762,7 +3762,7 @@ function uploadFile(webStore, filePath, publishFlg) {
core.debug(uploadRes);
if (publishFlg === 'true') {
webStore
.publish()
.publish(publishTarget)
.then((publishRes) => {
core.debug(publishRes);
})
Expand All @@ -3787,6 +3787,7 @@ function run() {
const refreshToken = core.getInput('refresh-token', { required: true });
const globFlg = core.getInput('glob');
const publishFlg = core.getInput('publish');
const publishTarget = core.getInput('publish-target');
const webStore = chrome_webstore_upload_1.default({
extensionId,
clientId,
Expand All @@ -3795,14 +3796,14 @@ function run() {
if (globFlg === 'true') {
const files = glob_1.default.sync(filePath);
if (files.length > 0) {
uploadFile(webStore, files[0], publishFlg);
uploadFile(webStore, files[0], publishFlg, publishTarget);
}
else {
core.setFailed('No files to match.');
}
}
else {
uploadFile(webStore, filePath, publishFlg);
uploadFile(webStore, filePath, publishFlg, publishTarget);
}
}
catch (error) {
Expand Down
14 changes: 10 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import fs from 'fs'
import glob from 'glob'
import chromeWebstoreUpload from 'chrome-webstore-upload'

function uploadFile(webStore: any, filePath: string, publishFlg: string): void {
function uploadFile(
webStore: any,
filePath: string,
publishFlg: string,
publishTarget: string
): void {
const myZipFile = fs.createReadStream(filePath)
webStore
.uploadExisting(myZipFile)
Expand All @@ -12,7 +17,7 @@ function uploadFile(webStore: any, filePath: string, publishFlg: string): void {
core.debug(uploadRes)
if (publishFlg === 'true') {
webStore
.publish()
.publish(publishTarget)
.then((publishRes: any) => {
core.debug(publishRes)
})
Expand Down Expand Up @@ -41,6 +46,7 @@ async function run(): Promise<void> {
const refreshToken = core.getInput('refresh-token', {required: true})
const globFlg = core.getInput('glob') as 'true' | 'false'
const publishFlg = core.getInput('publish') as 'true' | 'false'
const publishTarget = core.getInput('publish-target')

const webStore = chromeWebstoreUpload({
extensionId,
Expand All @@ -51,12 +57,12 @@ async function run(): Promise<void> {
if (globFlg === 'true') {
const files = glob.sync(filePath)
if (files.length > 0) {
uploadFile(webStore, files[0], publishFlg)
uploadFile(webStore, files[0], publishFlg, publishTarget)
} else {
core.setFailed('No files to match.')
}
} else {
uploadFile(webStore, filePath, publishFlg)
uploadFile(webStore, filePath, publishFlg, publishTarget)
}
} catch (error) {
core.setFailed((error as Error).message)
Expand Down

0 comments on commit c0debce

Please sign in to comment.