Skip to content

Commit

Permalink
Merge pull request #22 from gabrielogregorio/dev2
Browse files Browse the repository at this point in the history
docs: fix docs
  • Loading branch information
gabrielogregorio authored Feb 25, 2024
2 parents ae3d1f4 + 39e6d04 commit 06a33f3
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/create-tag-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
body: |
${{ env.BODY_RELEASE }}
make_latest: true
generate_release_notes: true
generate_release_notes: false
draft: false
prerelease: false
discussion_category_name: 'Announcements'
211 changes: 102 additions & 109 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,134 +1,65 @@
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`.
This action automates the release and tag creation process, using the github api [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)

## Using
### Prerequisites

```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
```
You need to configure your repository to allow this action to create the release and the tag, just go to settings, tag and release creation, just go to your settings, actions and general as shown in the screenshot below

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).
![./docs/access-config-actions.png](./docs/access-config-actions.png)

### 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
And then just go to the "Workflow permissions" section, check the "Read and write permissions" option and save. Now just re-execute this action

![./docs/select-permissions-workflows.png](./docs/select-permissions-workflows.png)

### Outputs
### Configuring a simpler action

- 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
Create a `.yml` file in the `.github/workflows` directory and configure the `gabrielogregorio/create-tag-and-release@v1.0.0` action specifying the version you want to use.

### Example workflow with body_path and discussion_category_name or merge or push in MAIN branch
Below is an example of how to use it with some more basic parameters

```yml
name: create tag and release on merge
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)
if: 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
- name: create tag and release
uses: gabrielogregorio/create-tag-and-release@v1.0.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'
tag_name: v2.5.0
release_name: Release 2.5
body: |
A example body
```
Example using version in package.json and pull request content
```yml
### Configuring a more complete action
The example below is much more complete, it handles push directly to `main`, or when merging pull requests. If you use the `master` branch or another branch, you will need to rename all references to main in the example below

In the `set config tag and release` step, various information is obtained, such as the version in `package.json`, the title of the pull request and its content, this is used to create releases in a pattern that I like.

```yml
name: create tag and release on merge pr
# when there is a push event in main or when a pull request is closed pointing to main
on:
push:
branches: [main]
Expand All @@ -138,6 +69,8 @@ on:
jobs:
create-release:
# If there is a push event pointing to main OR if there is a pull request event being merged
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
Expand All @@ -151,28 +84,28 @@ jobs:
node-version: 20.x
- name: set config tag and release
id: update-pr-content
run: |
# This is a trick to get the version of a package.json
PACKAGE_VERSION=$(node -p "require('./package.json').version")
# This is a way to read pull request information, such as title and body
PR_TITLE="${{ github.event.pull_request.title }}"
PR_BODY="${{ github.event.pull_request.body }}"
PACKAGE_VERSION=$(node -p "require('./package.json').version")
BODY_RELEASE="${PR_TITLE} ${PR_BODY}"
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
# This is a way to correctly save the line breaks contained in a pull request
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}"
RELEASE_NAME="Release v${PACKAGE_VERSION}"
echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_ENV
- name: create tag and release
uses: gabrielogregorio/create-tag-and-release@v1.2.0
uses: gabrielogregorio/create-tag-and-release@v1.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand All @@ -181,13 +114,73 @@ jobs:
body: |
${{ env.BODY_RELEASE }}
make_latest: true
generate_release_notes: true
generate_release_notes: false
draft: false
prerelease: false
# This is in case you want your release to be published as a discussion, in which case it will be published in the "Announcements" discussion
discussion_category_name: 'Announcements'
```
### Understanding Input Settings

The input parameters are inside `with`, example below

```yml
- name: create tag and release
uses: gabrielogregorio/create-tag-and-release@v1.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.TAG_NAME }} // input
release_name: ${{ env.RELEASE_NAME }} // input
body: ${{ env.BODY_RELEASE }} // input
make_latest: true // input
generate_release_notes: false // input
draft: false // input
prerelease: false // input
discussion_category_name: 'Announcements' // input
```

And they can be these values

- `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
This action will return the following 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

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

You can contribute by opening issues, discussions and even pull requests, fixing bugs or adding features that make sense for this project.

To contribute to pull requests, you need to configure node and yarn according to the package.json specifications. Additionally, you need to follow eslint, the commit pattern used in the project, build the application with your changes and open a pull request pointing to the dev branch.
Binary file added docs/access-config-actions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/select-permissions-workflows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 06a33f3

Please sign in to comment.