From 42382ed7d904be7e050d3361cf737e38f6ab24dd Mon Sep 17 00:00:00 2001 From: Ichinose Shogo Date: Thu, 30 Jan 2020 17:30:47 +0900 Subject: [PATCH] improve readme --- README.md | 167 ++++++++++++++++++++++++------------------------------ 1 file changed, 73 insertions(+), 94 deletions(-) diff --git a/README.md b/README.md index 95d96684..22be1744 100644 --- a/README.md +++ b/README.md @@ -1,117 +1,96 @@ -

- typescript-action status -

+# 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.