|
| 1 | +name: Bump Version and Tag Reusable Workflow |
| 2 | + |
| 3 | +description: | |
| 4 | + Get the would-be bumped version and version tag for a commit based on the |
| 5 | + changes since last version. |
| 6 | +inputs: |
| 7 | + bump_type: |
| 8 | + description: 'Version Bump Type' |
| 9 | + type: choice |
| 10 | + options: ['major', 'minor', 'patch', 'none'] |
| 11 | + required: false |
| 12 | + default: 'none' |
| 13 | + dry_run: |
| 14 | + description: 'Dry Run' |
| 15 | + type: boolean |
| 16 | + required: false |
| 17 | + default: false |
| 18 | + token: |
| 19 | + description: 'Token for AllenInstitute GitHub' |
| 20 | + required: true |
| 21 | +outputs: |
| 22 | + major: |
| 23 | + description: 'The major version number' |
| 24 | + value: ${{ steps.set-outputs.outputs.major }} |
| 25 | + minor: |
| 26 | + description: 'The minor version number' |
| 27 | + value: ${{ steps.set-outputs.outputs.minor }} |
| 28 | + patch: |
| 29 | + description: 'The patch version number' |
| 30 | + value: ${{ steps.set-outputs.outputs.patch }} |
| 31 | + increment: |
| 32 | + description: 'The increment. This is the number of commits since the last tag.' |
| 33 | + value: ${{ steps.set-outputs.outputs.increment }} |
| 34 | + version: |
| 35 | + description: 'The version number (e.g. 1.2.3)' |
| 36 | + value: ${{ steps.set-outputs.outputs.version }} |
| 37 | + version_tag: |
| 38 | + description: 'The version tag (e.g. v1.2.3)' |
| 39 | + value: ${{ steps.set-outputs.outputs.version_tag }} |
| 40 | + version_type: |
| 41 | + description: 'The version type (e.g. major, minor, patch, none)' |
| 42 | + value: ${{ steps.set-outputs.outputs.version_type }} |
| 43 | + previous_version: |
| 44 | + description: 'The previous version number (e.g. 1.2.2)' |
| 45 | + value: ${{ steps.set-outputs.outputs.previous_version }} |
| 46 | + |
| 47 | +runs: |
| 48 | + using: "composite" |
| 49 | + steps: |
| 50 | + - name: Bump patch version and tag |
| 51 | + id: bump-version-tag |
| 52 | + uses: anothrNick/[email protected] |
| 53 | + env: |
| 54 | + GITHUB_TOKEN: ${{ inputs.token }} |
| 55 | + DEFAULT_BUMP: ${{ inputs.bump_type || 'none' }} |
| 56 | + MAJOR_STRING_TOKEN: '(MAJOR)' |
| 57 | + MINOR_STRING_TOKEN: '(MINOR)' |
| 58 | + PATCH_STRING_TOKEN: '(PATCH)' |
| 59 | + NONE_STRING_TOKEN: '(NONE)' |
| 60 | + WITH_V: "true" |
| 61 | + RELEASE_BRANCHES: main |
| 62 | + DRY_RUN: true |
| 63 | + - name: Set Outputs |
| 64 | + id: set-outputs |
| 65 | + run: | |
| 66 | + new_tag=${{ steps.bump-version-tag.outputs.new_tag }} |
| 67 | + new_version=$(echo $new_tag | sed 's/^v//') |
| 68 | + major=$(echo $new_version | cut -d. -f1) |
| 69 | + minor=$(echo $new_version | cut -d. -f2) |
| 70 | + patch=$(echo $new_version | cut -d. -f3) |
| 71 | + increment=0 |
| 72 | + version_type=${{ steps.bump-version-tag.outputs.part }} |
| 73 | + previous_version=$(git describe --tags --abbrev=0 | sed 's/^v//') |
| 74 | +
|
| 75 | + echo "major=$major" >> $GITHUB_OUTPUT |
| 76 | + echo "minor=$minor" >> $GITHUB_OUTPUT |
| 77 | + echo "patch=$patch" >> $GITHUB_OUTPUT |
| 78 | + echo "increment=$increment" >> $GITHUB_OUTPUT |
| 79 | + echo "version=$new_version" >> $GITHUB_OUTPUT |
| 80 | + echo "version_tag=$new_tag" >> $GITHUB_OUTPUT |
| 81 | + echo "version_type=$version_type" >> $GITHUB_OUTPUT |
| 82 | + echo "previous_version=$previous_version" >> $GITHUB_OUTPUT |
| 83 | + shell: bash |
| 84 | + |
| 85 | + # Currently not using this Version bumping tool, but considering it for the future. |
| 86 | + # The main limitation is being able to override the default bump type even |
| 87 | + # if there are no commits. |
| 88 | + - name: Bump Version Alternate |
| 89 | + |
| 90 | + id: bump-version-tag-alt |
| 91 | + with: |
| 92 | + major_pattern: "/\\((MAJOR|BREAKING)\\)/" |
| 93 | + minor_pattern: "/\\((MINOR|FEATURE)\\)/" |
| 94 | + bump_each_commit: true |
| 95 | + bump_each_commit_patch_pattern: "/\\((PATCH|BUG)\\)/" |
| 96 | + - name: Set Outputs Alt |
| 97 | + id: set-outputs-alt |
| 98 | + shell: bash |
| 99 | + run: | |
| 100 | + echo 'changed: ${{ steps.bump-version-tag-alt.outputs.changed }}' |
| 101 | + echo 'major: ${{ steps.bump-version-tag-alt.outputs.major }}' |
| 102 | + echo 'minor: ${{ steps.bump-version-tag-alt.outputs.minor }}' |
| 103 | + echo 'patch: ${{ steps.bump-version-tag-alt.outputs.patch }}' |
| 104 | + echo 'increment: ${{ steps.bump-version-tag-alt.outputs.increment }}' |
| 105 | + echo 'version: ${{ steps.bump-version-tag-alt.outputs.version }}' |
| 106 | + echo 'version_tag: ${{ steps.bump-version-tag-alt.outputs.version_tag }}' |
| 107 | + echo 'version_type: ${{ steps.bump-version-tag-alt.outputs.version_type }}' |
| 108 | + echo 'previous_version: ${{ steps.bump-version-tag-alt.outputs.previous_version }}' |
| 109 | +
|
| 110 | + # echo "major=${{ steps.bump-version-tag-alt.outputs.major }}" >> $GITHUB_OUTPUT |
| 111 | + # echo "minor=${{ steps.bump-version-tag-alt.outputs.minor }}" >> $GITHUB_OUTPUT |
| 112 | + # echo "patch=${{ steps.bump-version-tag-alt.outputs.patch }}" >> $GITHUB_OUTPUT |
| 113 | + # echo "increment=${{ steps.bump-version-tag-alt.outputs.increment }}" >> $GITHUB_OUTPUT |
| 114 | + # echo "version=${{ steps.bump-version-tag-alt.outputs.version }}" >> $GITHUB_OUTPUT |
| 115 | + # echo "version_tag=${{ steps.bump-version-tag-alt.outputs.version_tag }}" >> $GITHUB_OUTPUT |
| 116 | + # echo "version_type=${{ steps.bump-version-tag-alt.outputs.version_type }}" >> $GITHUB_OUTPUT |
| 117 | + # echo "previous_version=${{ steps.bump-version-tag-alt.outputs.previous_version }}" >> $GITHUB_OUTPUT |
0 commit comments