Skip to content

Commit

Permalink
Merge pull request #30 from geoadmin/develop
Browse files Browse the repository at this point in the history
New Release v1.2.0 - #minor
  • Loading branch information
ltshb authored Nov 22, 2021
2 parents fe9f37f + 00ee30a commit 57f958c
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 4 deletions.
125 changes: 125 additions & 0 deletions .github/workflows/pr-auto-semver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: PR Auto Edit

# Auto PR Release Title. When creating a Release or Hotfix, the PR title is automatically set.
#
# For new release (develop -> master PR) the title is set to `New Release <next-version> - <bump-type>`
# with bump-type taken from the original title or from the change log commit message.
# By default bump-type if not specified or found is set to minor.
#
# For hotfix (hotfix-* -> master PR) the title is set to `<next-version> - <original-title> - <bump-type>`
#
# Finally add a Label to the PR based on HEAD branch name. These labels are then used to categorize
# the release notes.

on:
pull_request:
types:
- opened
- reopened
- synchronize
- edited

jobs:
pr-release-title:
name: Set PR title
runs-on: ubuntu-latest
if: ${{ github.base_ref == 'master' }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
ref: master

# This step is needed in order for the anothrNick/github-tag-action@1.33.0 action to work properly
- name: Do the merge but don't push it
run: |
cd ${GITHUB_WORKSPACE}
git config user.email "github@swisstopo.ch"
git config user.name "Github PR Auto Title Workflow"
git fetch origin ${{ github.head_ref }}:${{ github.head_ref }}
git merge ${{ github.head_ref }} --no-ff
- name: Get PR Infos
id: pr_infos
uses: Brymastr/pr-info-action@v1

- name: Get Bump Type and PR Title
id: bump_type
run: |
bump_type=minor
echo "Set Bump Type default to ${bump_type}"
# Set default bump type for hotfixes
case "${{ github.head_ref }}" in
hotfix-* | bugfix-* | bug-*)
bump_type=patch
echo "Hotfix detected set default bump to ${bump_type}"
;;
feat-* | feature-*)
bump_type=minor
echo "Hotfix detected set default bump to ${bump_type}"
;;
esac
echo "Set bump type based on PR infos"
case "${{ steps.pr_infos.outputs.body }}" in
*#major*) bump_type=major ;;
*#minor*) bump_type=minor ;;
*#patch*) bump_type=patch ;;
esac
case "${{ steps.pr_infos.outputs.title }}" in
*#major*) bump_type=major ;;
*#minor*) bump_type=minor ;;
*#patch*) bump_type=patch ;;
esac
echo "::set-output name=bump::${bump_type}"
echo "Bump type set to ${bump_type}"
echo "Remove bump type from original title"
pr_title="${{ steps.pr_infos.outputs.title }}"
pr_title="${pr_title//[#]$bump_type/}"
echo "::set-output name=pr_title::${pr_title}"
- name: Bump version (without tagging)
id: get_tag
uses: anothrNick/github-tag-action@1.33.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: ${{ steps.bump_type.outputs.bump }}
RELEASE_BRANCHES: master
TAG_CONTEXT: repo
DRY_RUN: true

- name: Set `New Release` PR title if needed
if: ${{ github.head_ref == 'develop' }}
uses: juztcode/pr-updater@1.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "New Release ${{ steps.get_tag.outputs.new_tag }} - #${{ steps.bump_type.outputs.bump }}"
body: ${{ steps.pr_infos.outputs.body }}

- name: Set `Hotfix` PR title if needed
if: ${{ github.head_ref != 'develop' }}
uses: juztcode/pr-updater@1.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "${{ steps.get_tag.outputs.new_tag }} - ${{ steps.bump_type.outputs.pr_title }} - #${{ steps.bump_type.outputs.bump }}"
body: ${{ steps.pr_infos.outputs.body }}

pr-labeler:
name: Set PR label
runs-on: ubuntu-latest
steps:
- name: PR Auto Labeler
uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter-labeler-config.yml
disable-autolabeler: false
disable-releaser: true

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ title attached to the PR or based on the `milestone_pattern` input (default to `
| `custom_tag` | String | `${MILESTONE}` | Custom tag to set. Several placeholders can be used, see [Custom Tag Placeholders](#custom-tag-placeholders). |
| `initial_tag_number` | Number | `1` | Initial `TAG_NUMBER` placeholder. |
| `milestone_pattern` | String | `.+?` | Milestone pattern used to search for previous tag when not milestone is attached. |
| `milestone` | String | `''` | Milestone value to use for tagging (overwrite the milestone attached to the PR) |
| `dry_run` | Bool | `false` | Dry run for testing, do not create the tag. |

### Custom Tag Placeholders
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ inputs:
milestone_pattern:
default: '.+?'
description: 'Milestone pattern used to search previous tag'
milestone:
default: null
description: 'Milestone value to use for tag (overwrite the value attached to the PR)'
dry_run:
default: false
description: 'Dry run for testing, do not create the tag if set to true.'
Expand Down
5 changes: 4 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "action-milestone-tag",
"version": "1.1.0",
"version": "1.2.0",
"private": true,
"description": "Github action to tag the repository with the milestone title",
"main": "lib/main.js",
Expand Down
5 changes: 4 additions & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ async function computeTags(
const custom_tag = core.getInput('custom_tag')
const initial_tag_number = Number(core.getInput('initial_tag_number'))
const milestone_pattern = core.getInput('milestone_pattern')
const milestone = pullRequest.milestone ? pullRequest.milestone.title : null
let milestone = core.getInput('milestone')
if (!milestone) {
milestone = pullRequest.milestone ? pullRequest.milestone.title : null
}
checkMilestone(milestone, milestone_pattern)
core.info(`PR milestone: ${milestone}`)
const tagPattern = getTagPattern(custom_tag, milestone_pattern, milestone)
Expand Down

0 comments on commit 57f958c

Please sign in to comment.