Skip to content

Commit

Permalink
feat: first commmit
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielogregorio committed Feb 25, 2024
1 parent 2c6a798 commit 3bf4929
Show file tree
Hide file tree
Showing 20 changed files with 36,187 additions and 1,662 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
test
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"plugins": ["@typescript-eslint", "import"],
"rules": {
"no-console": "off",
"import/extensions": "off",
"import/prefer-default-export": "off",
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/create-tag-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: create tag and release on merge pr

on:
push:
branches: [main]
pull_request:
types: [closed]
branches: [main]

jobs:
create-release:
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
with:
ref: main

- name: set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: set config tag and release
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
PR_TITLE="${{ github.event.pull_request.title }}"
PR_BODY="${{ github.event.pull_request.body }}"
BODY_RELEASE="${PR_TITLE} ${PR_BODY}"
echo "BODY_RELEASE<<EOF" >> $GITHUB_ENV
echo "$BODY_RELEASE" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
TAG_NAME="v${PACKAGE_VERSION}"
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
RELEASE_NAME="v${PACKAGE_VERSION}"
echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_ENV
- name: create tag and release
uses: gabrielogregorio/create-tag-and-release@v0.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.TAG_NAME }}
release_name: ${{ env.RELEASE_NAME }}
body: |
${{ env.BODY_RELEASE }}
make_latest: true
generate_release_notes: true
draft: false
prerelease: false
discussion_category_name: 'Announcements'
4 changes: 0 additions & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn format
yarn lint
yarn lint-tsc

npx lint-staged
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.md
dist/
dist/*.js
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
},
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"typescript.preferences.importModuleSpecifier": "non-relative",
"files.autoSave": "afterDelay"
}
191 changes: 191 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,193 @@
test
Actions.yml https://docs.github.com/pt/actions/creating-actions/metadata-syntax-for-github-actions


Actions > Runners > Workflow permissions > Read and write permissions > [save]


# GitHub Action - Create tag and release

Essa action foi feita para usar a documentação oficial do github para a criação de releases [https://docs.github.com/pt/rest/releases/releases?apiVersion=2022-11-28#create-a-release](https://docs.github.com/pt/rest/releases/releases?apiVersion=2022-11-28#create-a-release)

Esta ação do GitHub (escrita em JavaScript) envolve a [API de lançamento do GitHub](https://developer.github.com/v3/repos/releases/), especificamente a [Criar uma versão](https://developer.github. com/v3/repos/releases/#create-a-release), para permitir que você aproveite GitHub Actions para criar versões.


## Usage
### Pré requisitos

Crie um arquivo `.yml` no diretório `.github/workflows`.


```yml
name: create tag and release on merge pr
on:
push:
branches: [main]
pull_request:
types: [closed]
branches: [main]

jobs:
create-release:
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
runs-on: ubuntu-latest
steps:
- name: create release and tag
uses: gabrielogregorio/create-tag-and-release@v1.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v1.0.0
release_name: Release V1.0.0
body: |
Release content
draft: false
prerelease: false
```
Ou você pode usar um exemplo mais sofisticado, que cria a release com o conteudo do README, cria as tags e versões de acordo com o seu package.json [usamos esse yml para criar as tags e releases desse projeto](./.github/workflows/create-tag-and-release.yml).
### Inputs
- `tag_name`: (REQUIRED) The name of the tag.
- `release_name`: The name of the release.
- `body`: body of release
- `body_path`: file that will contain the release body. If informed, body will be disregarded
- `draft`: true to create a draft (unpublished) release, false to create a published one. Default: false
- `prerelease`:true to identify the release as a prerelease. false to identify the release as a full release. Padrão: false
- `target_commitish`: Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists. Default: the repository's default branch.
- `owner`:The account owner of the repository. The name is not case sensitive. Default Current repository
- `repo`:The name of the repository without the .git extension. The name is not case sensitive. Default Current owner
- `discussion_category_name`: If specified, a discussion of the specified category is created and linked to the release. The value must be a category that already exists in the repository. For more information, see "Managing categories for discussions in your repository."
- `generate_release_notes`:Whether to automatically generate the name and body for this release. If name is specified, the specified name will be used; otherwise, a name will be automatically generated. If body is specified, the body will be pre-pended to the automatically generated notes. Padrão: false
- `make_latest`:Specifies whether this release should be set as the latest release for the repository. Drafts and prereleases cannot be set as latest. Defaults to true for newly published releases. legacy specifies that the latest release should be determined based on the release creation date and higher semantic version. Padrão: true


### Outputs

- id
- status
- url
- assets_url
- upload_url
- html_url
- author
- tag_name
- target_commitish
- name
- draft
- prerelease
- assets
- body
- discussion_url
- published_at
- created_at

### Example workflow with body_path and discussion_category_name or merge or push in MAIN branch

```yml
name: create tag and release on merge
on:
push:
branches: [main]
pull_request:
types: [closed]
branches: [main]
jobs:
create-release:
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
with:
ref: main
- name: set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: create release and tag
uses: gabrielogregorio/create-tag-and-release@v1.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v5.1.2
release_name: Release Name - v5.1.2
body_path: './docs/example.md'
make_latest: true
generate_release_notes: true
draft: false
prerelease: false
discussion_category_name: 'Announcements'
```

Example using version in package.json and pull request content
```yml
name: create tag and release on merge pr
on:
push:
branches: [main]
pull_request:
types: [closed]
branches: [main]
jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
with:
ref: main
- name: set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: set config tag and release
id: update-pr-content
run: |
PR_TITLE="${{ github.event.pull_request.title }}"
PR_BODY="${{ github.event.pull_request.body }}"
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if [ "${{ github.event_name }}" = "pull_request" ]; then
PR_TITLE="${{ github.event.pull_request.title }}"
PR_BODY="${{ github.event.pull_request.body }}"
BODY_RELEASE="${PR_TITLE}: ${PR_BODY}"
else
BODY_RELEASE="Release ${TAG_NAME}"
fi
TAG_NAME="v${PACKAGE_VERSION}"
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
RELEASE_NAME="v${PACKAGE_VERSION}"
echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_ENV
- name: create tag and release
uses: gabrielogregorio/create-tag-and-release@v1.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.TAG_NAME }}
release_name: ${{ env.RELEASE_NAME }}
body: |
${{ env.BODY_RELEASE }}
make_latest: true
generate_release_notes: true
draft: false
prerelease: false
discussion_category_name: 'Announcements'
```


## Contributing
We would love you to contribute to `@actions/create-release`, pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information.

81 changes: 70 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,86 @@
name: 'Create Release And Tag'
description: 'Create release and tag'
name: 'Create Tag And Release'
description: 'Create tag and release'
author: 'Gabriel Gregório'
inputs:
tag_name:
description: 'The tag name'
description: 'The name of the tag.'
required: true
release_name:
description: 'The release name'
required: true
description: 'The name of the release.'
required: false
body:
description: 'The body'
description: 'body of release'
required: false
body_path:
description: 'file that will contain the release body. If informed, body will be disregarded'
required: false
draft:
description: 'true to create a draft (unpublished) release, false to create a published one. Default: false'
required: false
default: false
prerelease:
description: 'true to identify the release as a prerelease. false to identify the release as a full release. Padrão: false'
required: false
default: false
target_commitish:
description: "Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists. Default: the repository's default branch."
required: false
owner:
description: 'The account owner of the repository. The name is not case sensitive.'
required: false
repo:
description: 'The name of the repository without the .git extension. The name is not case sensitive.'
required: false
discussion_category_name:
description: 'If specified, a discussion of the specified category is created and linked to the release. The value must be a category that already exists in the repository. For more information, see "Managing categories for discussions in your repository."'
required: false
generate_release_notes:
description: 'Whether to automatically generate the name and body for this release. If name is specified, the specified name will be used; otherwise, a name will be automatically generated. If body is specified, the body will be pre-pended to the automatically generated notes. Padrão: false'
required: false
default: false
make_latest:
description: 'Specifies whether this release should be set as the latest release for the repository. Drafts and prereleases cannot be set as latest. Defaults to true for newly published releases. legacy specifies that the latest release should be determined based on the release creation date and higher semantic version. Padrão: true'
required: false
default: true

outputs:
id:
description: 'The ID'
html_url:
description: 'The html url'
description: 'release id'
status:
description: 'status code response'
url:
description: 'url'
assets_url:
description: 'assets_url'
upload_url:
description: 'The upload url'
description: 'upload_url'
html_url:
description: 'html_url'
author:
description: 'author'
tag_name:
description: 'tag_name'
target_commitish:
description: 'target_commitish'
name:
description: 'name'
draft:
description: 'draft'
prerelease:
description: 'prerelease'
assets:
description: 'assets'
body:
description: 'body'
discussion_url:
description: 'discussion_url'
published_at:
description: 'published_at'
created_at:
description: 'created_at'

runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'

branding:
Expand Down
Loading

0 comments on commit 3bf4929

Please sign in to comment.