-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (110 loc) · 4.85 KB
/
bump_version.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: Bump Version and Tag
on:
push:
branches: [ main ]
paths-ignore:
- '**/_version.py'
workflow_dispatch:
inputs:
bump_type:
description: 'Version bump type to use. If target_version is set, this will be ignored.'
type: choice
options: ['major', 'minor', 'patch', 'none']
required: false
default: 'none'
target_version:
description: |
Optional target version (e.g. 1.2.3) to bump to. If not set, bump type will be used.
(leave empty for default)
required: false
default: ''
dry_run:
description: 'Dry Run'
type: boolean
required: false
default: false
jobs:
get-version-info:
name: Get New Version Tag
runs-on: ubuntu-latest
if: github.actor != 'github-actions[bot]'
outputs:
version: ${{ steps.set-target-version.outputs.version || steps.version-tag.outputs.version }}
version_tag: ${{ steps.set-target-version.outputs.version_tag || steps.version-tag.outputs.version_tag }}
version_type: ${{ steps.set-target-version.outputs.version_type || steps.version-tag.outputs.version_type }}
previous_version: ${{ steps.get-current-version.outputs.previous_version || steps.version-tag.outputs.previous_version }}
update_required: ${{ steps.set-update-required.outputs.update_required }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get Bumped Version Tag
uses: ./.github/actions/bump-version-tag
id: version-tag
with:
bump_type: ${{ github.event.inputs.bump_type }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Print Version Info
# We only want to print if we are not a workflow call or if the target version is 'N/A'
if: github.event_name != 'workflow_dispatch' || !inputs.target_version
run: |
echo "Version: ${{ steps.version-tag.outputs.version }}"
echo "Version Tag: ${{ steps.version-tag.outputs.version_tag }}"
echo "Version Type: ${{ steps.version-tag.outputs.version_type }}"
echo "Previous Version: ${{ steps.version-tag.outputs.previous_version }}"
- name: Set Target Version
id: set-target-version
# We only want to set the target version if we are a workflow call and the target version is set
if: github.event_name == 'workflow_dispatch' && inputs.target_version
run: |
echo "Setting target version to ${{ inputs.target_version }}"
echo "version=${{ inputs.target_version }}" >> $GITHUB_OUTPUT
echo "version_tag=v${{ inputs.target_version }}" >> $GITHUB_OUTPUT
- name: Get Current Version
id: get-current-version
# We only want to get current version if we are a workflow call and the target version is set
if: github.event_name == 'workflow_dispatch' && inputs.target_version
uses: ./.github/actions/source-code-version-get
with:
version_file: _version.py
- name: Set Update Required
id: set-update-required
run: |
if [ "${{ steps.set-target-version.outputs.version || steps.version-tag.outputs.version }}" != "${{ steps.version-tag.outputs.previous_version }}" ]; then
echo "Update required"
echo "update_required=true" >> $GITHUB_OUTPUT
else
echo "No update required"
echo "update_required=false" >> $GITHUB_OUTPUT
fi
update-version-and-tag:
name: Update Repo Tag and Version
runs-on: ubuntu-latest
needs: get-version-info
# We only want to run if:
# 1. We are not the GitHub bot
# 2. We are not a workflow call or we are not in dry run mode
# 3. The update is required (i.e. the version has changed)
if: |
github.actor != 'github-actions[bot]' &&
(github.event_name != 'workflow_dispatch' || !inputs.dry_run) &&
needs.get-version-info.outputs.update_required == 'true'
steps:
- uses: actions/checkout@v4
# This sets up the git user for the GitHub bot
- name: Configure Git User
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# This sets up ssh keys for the AllenInstitute GitHub
- name: Configure AllenInstitute Repo Authorization
uses: ./.github/actions/configure-org-repo-authorization
with:
token: ${{ secrets.AI_PACKAGES_TOKEN }}
ssh_private_key: ${{ secrets.AIBSGITHUB_PRIVATE_KEY }}
- name: Update Version
uses: ./.github/actions/source-code-version-update
with:
version: ${{ needs.get-version-info.outputs.version }}
version_tag: ${{ needs.get-version-info.outputs.version_tag }}
version_file: _version.py