generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from snow-actions/feature/tweet
Tweet
- Loading branch information
Showing
12 changed files
with
33,832 additions
and
572 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
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,101 +1,63 @@ | ||
<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> | ||
<a href="https://github.com/snow-actions/tweet/actions"><img alt="snow-actions/tweet status" src="https://github.com/snow-actions/tweet/workflows/build-test/badge.svg"></a> | ||
</p> | ||
|
||
# Create a JavaScript Action using TypeScript | ||
|
||
Use this template to bootstrap the creation of a TypeScript action.:rocket: | ||
|
||
This template includes compilation support, tests, a validation workflow, publishing, and versioning guidance. | ||
|
||
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action) | ||
|
||
## Create an action from this template | ||
|
||
Click the `Use this Template` and provide the new repo details for your action | ||
|
||
## Code in Main | ||
|
||
Install the dependencies | ||
```bash | ||
$ npm install | ||
``` | ||
|
||
Build the typescript and package it for distribution | ||
```bash | ||
$ npm run build && npm run package | ||
``` | ||
|
||
Run the tests :heavy_check_mark: | ||
```bash | ||
$ npm test | ||
|
||
PASS ./index.test.js | ||
✓ throws invalid number (3ms) | ||
✓ wait 500 ms (504ms) | ||
✓ test runs (95ms) | ||
|
||
... | ||
``` | ||
|
||
## 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 | ||
|
||
Most toolkit and CI/CD operations involve async operations so the action is run in an async function. | ||
|
||
```javascript | ||
import * as core from '@actions/core'; | ||
... | ||
|
||
async function run() { | ||
try { | ||
... | ||
} | ||
catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
|
||
run() | ||
# Tweet action | ||
Tweet via GitHub Actions. | ||
|
||
## Usage | ||
|
||
1. Create your Twitter App in [developer.twitter.com](https://developer.twitter.com/en/apps). | ||
1. Set secrets `TWITTER_CONSUMER_API_KEY`, `TWITTER_CONSUMER_API_SECRET_KEY`, `TWITTER_ACCESS_TOKEN`, `TWITTER_ACCESS_TOKEN_SECRET` in settings. | ||
1. Create workflow YAML. | ||
|
||
```yml | ||
name: 'tweet' | ||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
tweet: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Tweet | ||
id: tweet | ||
uses: snow-actions/[email protected] | ||
env: | ||
CONSUMER_API_KEY: ${{ secrets.TWITTER_CONSUMER_API_KEY }} | ||
CONSUMER_API_SECRET_KEY: ${{ secrets.TWITTER_CONSUMER_API_SECRET_KEY }} | ||
ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} | ||
ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} | ||
with: | ||
status: ${{ github.run_id }}-${{ github.run_number }} ${{ github.sha }} | ||
- run: echo ${{ steps.tweet.outputs.response }} | ||
``` | ||
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages. | ||
## Environments | ||
Authentication parameters. | ||
## Publish to a distribution branch | ||
|name|required|description| | ||
|---|---|---| | ||
|CONSUMER_API_KEY|required|Consumer API key| | ||
|CONSUMER_API_SECRET_KEY|required|Consumer API secret key| | ||
|ACCESS_TOKEN|required|Access token| | ||
|ACCESS_TOKEN_SECRET|required|Access token secret| | ||
Actions are run from GitHub repos so we will checkin the packed dist folder. | ||
## Inputs & Outputs | ||
See [action.yml](action.yml) and [Twitter API reference](https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-statuses-update). | ||
Then run [ncc](https://github.com/zeit/ncc) and push the results: | ||
```bash | ||
$ npm run package | ||
$ git add dist | ||
$ git commit -a -m "prod dependencies" | ||
$ git push origin releases/v1 | ||
``` | ||
|
||
Your action is now published! :rocket: | ||
|
||
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) | ||
|
||
## Validate | ||
|
||
You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml)) | ||
|
||
```yaml | ||
uses: ./ | ||
with: | ||
milliseconds: 1000 | ||
``` | ||
### Inputs | ||
Request parameters. | ||
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket: | ||
|name|required|description| | ||
|---|---|---| | ||
|status|required|The text of the status update. URL encode as necessary. [t.co link wrapping](https://developer.twitter.com/en/docs/basics/tco) will affect character counts.| | ||
## Usage: | ||
### Outputs | ||
Response. | ||
After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and latest V1 action | ||
|name|description| | ||
|---|---| | ||
|response|Response JSON| |
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
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,11 +1,16 @@ | ||
name: 'Your name here' | ||
description: 'Provide a description here' | ||
author: 'Your name or organization here' | ||
name: 'Tweet' | ||
description: 'Tweet action' | ||
author: 'SnowCait' | ||
inputs: | ||
milliseconds: # change this | ||
status: | ||
required: true | ||
description: 'input description here' | ||
default: 'default value if applicable' | ||
description: 'The text of the status update. URL encode as necessary. t.co link wrapping will affect character counts.' | ||
outputs: | ||
response: | ||
description: 'Response JSON' | ||
runs: | ||
using: 'node12' | ||
main: 'dist/index.js' | ||
branding: | ||
icon: 'edit' | ||
color: 'blue' |
Oops, something went wrong.