feat: Updated README.md #161
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: PR | |
on: | |
push: | |
branches-ignore: | |
- master | |
- gh-pages | |
tags-ignore: | |
- '*' | |
jobs: | |
create_pull_request: | |
name: Create or update a pull request | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2.4.0 | |
with: | |
persist-credentials: false | |
fetch-depth: 0 | |
- name: Generate new changelog | |
run: | | |
initial_commit=$( git log --reverse --format='%H' | head -n 1 ) | |
printf '\n\ninitial_commit=%s\n\n' "${initial_commit[@]}" | |
output='' | |
for tag in $( git tag -l ); do | |
printf 'Processing tag=%s\n' "${tag[@]}" | |
commits=$( git log --reverse --format='* (%h) %s (%an)' "${initial_commit}".."${tag}" ) | |
if [ ${#commits[@]} -eq 0 ]; then | |
commits=$( git log --reverse --format='* (%h) %s (%an)' | head -n 1 ) | |
fi | |
printf 'commits=<<<COMMITS\n%s\nCOMMITS\n' "${commits[@]}" | |
section=$( printf '%s\n%s' "## v${tag}" "${commits}" ) | |
initial_commit="${tag}" | |
step_output=$( printf '%s\n\n' "${section}" ) | |
printf 'version_changelog=<<<CHUNK\n%s\nCHUNK\n\n' "${step_output[@]}" | |
output=$( printf '%s\n\n' "${step_output}" "${output}" ) | |
done | |
package_version=$( cat package.json | grep "version" | grep -oE '[0-9.]+' ) | |
last_tag=$( git tag -l | tail -n 1 ) | |
printf 'package_version=%s\nlast_tag=%s\n' "${package_version[@]}" "${last_tag[@]}" | |
if [ "${package_version}" != "${last_tag}" ]; then | |
commits=$( git log --reverse --format='* (%h) %s (%an)' "${last_tag}"..HEAD ) | |
if [ ${#commits[@]} -ne 0 ]; then | |
section=$( printf '%s\n%s' "## v${package_version}" "${commits}" ) | |
output=$( printf '%s\n\n' "${section}" "${output}" ) | |
fi | |
fi | |
printf 'Changelog=<<<CHANGELOG\n%s\nCHANGELOG\n\n' "${output[@]}" | |
printf '%s\n' "${output}" > CHANGELOG.md | |
- name: Upload new changelog | |
uses: actions/upload-artifact@v2.2.4 | |
with: | |
name: changelog | |
path: CHANGELOG.md | |
- name: Commit and push the new changelog | |
run: | | |
if [ -z $(git status -uno --porcelain) ]; then | |
printf 'Changelogs are idential, nothing to commit\n' | |
else | |
printf 'Committing the updated changelog\n' | |
git config --local user.name "github-actions[bot]" | |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git add CHANGELOG.md | |
git commit -am "Update the project changelog" | |
fi | |
- name: Push changes | |
uses: ad-m/github-push-action@v0.6.0 | |
with: | |
github_token: '${{ secrets.GITHUB_TOKEN }}' | |
branch: '${{ github.ref }}' | |
- name: Generate the changelog for this pull request | |
id: generate-changelog | |
run: | | |
CURRENT_BRANCH="${GITHUB_SHA}" | |
pr_title="$( git log --reverse --format='%s' "origin/${MAIN_BRANCH}".."${CURRENT_BRANCH}" | head -n 1 )" | |
pr_changelog="$( git log --reverse --format='* (%h) %s (%an)' "origin/${MAIN_BRANCH}".."${CURRENT_BRANCH}" )" | |
pr_description=$( echo "## ${pr_title}"; echo; echo; echo "### Changelog"; echo; echo "${pr_changelog}" ) | |
echo "PR_TITLE<<EOF" >> ${GITHUB_ENV} | |
echo "${pr_title}" >> ${GITHUB_ENV} | |
echo 'EOF' >> ${GITHUB_ENV} | |
echo "PR_DESCRIPTION<<EOF" >> ${GITHUB_ENV} | |
echo "${pr_description}" >> ${GITHUB_ENV} | |
echo 'EOF' >> ${GITHUB_ENV} | |
env: | |
MAIN_BRANCH: '${{ secrets.NEW_PR_DEFAULT_DESTINATION_BRANCH }}' | |
- name: Create a pull request | |
uses: repo-sync/pull-request@v2.6.1 | |
with: | |
source_branch: '' | |
destination_branch: '${{ secrets.NEW_PR_DEFAULT_DESTINATION_BRANCH }}' | |
pr_title: '${{ env.PR_TITLE }}' | |
pr_body: '${{ env.PR_DESCRIPTION }}' | |
pr_reviewer: '${{ secrets.NEW_PR_DEFAULT_REVIEWERS }}' | |
pr_assignee: '${{ secrets.NEW_PR_DEFAULT_ASSIGNEES }}' | |
pr_label: '${{ secrets.NEW_PR_DEFAULT_LABELS }}' | |
pr_milestone: '${{ secrets.NEW_PR_DEFAULT_MILESTONE }}' | |
github_token: '${{ secrets.GITHUB_TOKEN }}' | |
- name: Update pull request | |
uses: kt3k/update-pr-description@v1.0.4 | |
with: | |
pr_title: '${{ env.PR_TITLE }}' | |
pr_body: '${{ env.PR_DESCRIPTION }}' | |
github_token: '${{ secrets.GITHUB_TOKEN }}' |