generated from actions/typescript-action
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ba1b3d
commit 42382ed
Showing
1 changed file
with
73 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,96 @@ | ||
<p align="center"> | ||
<a href="https://github.com/actions/typescript-action/actions"><img alt="typescript-action status" src="https://github.com/actions/typescript-action/workflows/build-test/badge.svg"></a> | ||
</p> | ||
# GitHub Action - Releases API | ||
|
||
# Create a JavaScript Action using TypeScript | ||
![test](https://github.com/shogo82148/actions-upload-release-asset/workflows/test/badge.svg) | ||
|
||
Use this template to bootstrap the creation of a JavaScript action.:rocket: | ||
This GitHub Action uploads release assets using [Upload a release asset](https://developer.github.com/v3/repos/releases/#upload-a-release-asset). | ||
|
||
This template includes compilication support, tests, a validation workflow, publishing, and versioning guidance. | ||
## SYNOPSIS | ||
|
||
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action) | ||
### Upload assets when a release has been created | ||
|
||
## Create an action from this template | ||
You can upload assets when [a release has been created](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#release-event-release). | ||
|
||
Click the `Use this Template` and provide the new repo details for your action | ||
|
||
## Code in Master | ||
|
||
Install the dependencies | ||
```bash | ||
$ npm install | ||
``` | ||
|
||
Build the typescript | ||
```bash | ||
$ npm run build | ||
``` | ||
|
||
Run the tests :heavy_check_mark: | ||
```bash | ||
$ npm test | ||
|
||
PASS ./index.test.js | ||
✓ throws invalid number (3ms) | ||
✓ wait 500 ms (504ms) | ||
✓ test runs (95ms) | ||
|
||
... | ||
```yaml | ||
on: | ||
release: | ||
types: | ||
- created | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
# steps for building assets | ||
- run: echo "REPLACE ME!" > assets.txt | ||
|
||
- uses: shogo82148/actions-upload-release-asset@v1 | ||
with: | ||
upload_url: ${{ github.event.release.upload_url }} | ||
asset_path: assets.txt | ||
``` | ||
## Change action.yml | ||
|
||
The action.yml contains defines the inputs and output for your action. | ||
|
||
Update the action.yml with your name, description, inputs and outputs for your action. | ||
|
||
See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions) | ||
|
||
## Change the Code | ||
### Upload assets when a tag has been created | ||
Most toolkit and CI/CD operations involve async operations so the action is run in an async function. | ||
If you want to create a release in your workflow, you can use [actions/create-release](https://github.com/actions/create-release) GitHub Action. | ||
```javascript | ||
import * as core from '@actions/core'; | ||
... | ||
|
||
async function run() { | ||
try { | ||
... | ||
} | ||
catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
|
||
run() | ||
```yaml | ||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
# steps for building assets | ||
- run: echo "REPLACE ME!" > assets.txt | ||
|
||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1.0.0 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: Release ${{ github.ref }} | ||
draft: false | ||
prerelease: false | ||
|
||
- uses: shogo82148/actions-upload-release-asset@v1 | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: assets.txt | ||
``` | ||
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages. | ||
## Inputs | ||
## Publish to a distribution branch | ||
### github_token | ||
Actions are run from GitHub repos. We will create a releases branch and only checkin production modules (core in this case). | ||
The API token for GitHub. | ||
`${{ github.token }}` is used by default. | ||
|
||
Comment out node_modules in .gitignore and create a releases/v1 branch | ||
```bash | ||
# comment out in distribution branches | ||
# node_modules/ | ||
``` | ||
### upload_url | ||
|
||
```bash | ||
$ git checkout -b releases/v1 | ||
$ git commit -a -m "prod dependencies" | ||
``` | ||
The URL for uploading assets to the release. | ||
|
||
```bash | ||
$ npm prune --production | ||
$ git add node_modules | ||
$ git commit -a -m "prod dependencies" | ||
$ git push origin releases/v1 | ||
``` | ||
### asset_path | ||
|
||
Your action is now published! :rocket: | ||
The path to the asset you want to upload. | ||
You can use [glob patterns](https://github.com/actions/toolkit/tree/master/packages/glob#patterns) here. | ||
|
||
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) | ||
### asset_name | ||
|
||
## Validate | ||
The name of the asset you want to upload. | ||
The file name of `asset_path` is used by default. | ||
|
||
You can now validate the action by referencing the releases/v1 branch | ||
### asset_content_type | ||
|
||
```yaml | ||
uses: actions/typescript-action@releases/v1 | ||
with: | ||
milliseconds: 1000 | ||
``` | ||
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket: | ||
## Usage: | ||
The content-type of the asset you want to upload. | ||
See the supported Media Types here: https://www.iana.org/assignments/media-types/media-types.xhtml for more information. | ||
|
||
After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and tested action | ||
```yaml | ||
uses: actions/typescript-action@v1 | ||
with: | ||
milliseconds: 1000 | ||
``` | ||
By default, the actions guess the content-type using the [mime-types](https://www.npmjs.com/package/mime-types) package. |