Update README.md #469
Workflow file for this run
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
name: auto-release-when-pr-is-merged | |
on: | |
pull_request: | |
types: | |
- closed | |
branches: | |
- main | |
jobs: | |
draft-release: | |
if: ${{ github.event.pull_request.merged == true && ! contains( github.event.pull_request.labels.*.name, 'release') }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: prepare release tag | |
run: echo "release_tag=v$(date '+%Y%m%d_%H%M%S')" >> "$GITHUB_ENV" | |
- uses: actions/github-script@v6 | |
with: | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `PR has been merged. we're processing it! (${new Date()})` | |
}) | |
- name: Create Release | |
id: release | |
uses: actions/create-release@v1 # not maintained | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ env.release_tag }} | |
release_name: ${{ env.release_tag }} | |
body: | | |
This release is automatically created by [GitHub Actions auto-release-when-pr-is-merged.yml](https://github.com/nakamasato/github-actions-practice/blob/master/.github/workflows/auto-release-when-pr-is-merged.yml). | |
Triggered PR: [${{ github.event.number }}:${{ github.event.pull_request.title }}](${{ github.event.pull_request.html_url }}) created by ${{ github.actor }} | |
draft: true | |
prerelease: false | |
- uses: actions/github-script@v6 | |
with: | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `Draft release ([${{ steps.release.outputs.id }}](${{ steps.release.outputs.html_url }})) has been created. (${new Date()})` | |
}) | |
release: | |
if: ${{ github.event.pull_request.merged == true && contains( github.event.pull_request.labels.*.name, 'release') }} | |
runs-on: ubuntu-latest | |
env: | |
PUBLISH_RELEASE_SCRIPT: ./.publish-release.sh | |
steps: | |
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 | |
with: | |
ref: main | |
- uses: actions/github-script@v6 | |
with: | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `PR has been merged. we're publishing a new release! (${new Date()})` | |
}) | |
- name: git config | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Actions" | |
- name: release | |
id: release | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
sh "$PUBLISH_RELEASE_SCRIPT" | |
release_tag=$(gh release view --json tagName | jq -r .tagName) | |
release_url=$(gh release view --json url | jq -r .url) | |
echo "release_tag=$release_tag" >> "$GITHUB_OUTPUT" | |
echo "release_url=$release_url" >> "$GITHUB_OUTPUT" | |
- uses: actions/github-script@v6 | |
with: | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `New release [${{ steps.release.outputs.release_tag }}](${{ steps.release.outputs.release_url }}) has been published! (${new Date()})` | |
}) |