Skip to content

Commit ebccbe2

Browse files
authored
Merge pull request #1 from AllenInstitute/feature/misc-stuff
Add new GH actions, new lambda functions, core/auth updates, version changes
2 parents 2376289 + 3dbb13d commit ebccbe2

File tree

13 files changed

+466
-20
lines changed

13 files changed

+466
-20
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
uses: PaulHatch/[email protected]
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

.github/actions/setup-ai-github-urls/action.yml renamed to .github/actions/configure-org-repo-authorization/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: AllenInstitute Repo Setup
1+
name: AllenInstitute Repo Permissions Setup
22

33
description: |
44
Configures all credentials to use AllenInstitute Repos in GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
name: Get Version from Source Code
3+
4+
description: |
5+
Get the version from the source code and output the version and tag.
6+
7+
inputs:
8+
version_file:
9+
description: 'The file containing the version number'
10+
default: '_version.py'
11+
required: false
12+
version_regex:
13+
description: 'The regex to extract the version number'
14+
default: "__version__ = (?:\"|')([0-9]+\.[0-9]+\.[0-9]+)(?:\"|')"
15+
required: false
16+
version_tag_prefix:
17+
description: 'The prefix for the version tag'
18+
required: false
19+
default: 'v'
20+
outputs:
21+
version:
22+
description: 'The version number (e.g. 1.2.3)'
23+
version_tag:
24+
description: 'The version tag (e.g. v1.2.3)'
25+
26+
runs:
27+
using: "composite"
28+
steps:
29+
- name: Get Version
30+
id: get-version
31+
run: |
32+
version=$(find . -name ${{ inputs.version_file }} -exec cat {} \; | grep -oP -m 1 "${{ inputs.version_regex }}")
33+
echo "Version: $version"
34+
echo "version=$version" >> $GITHUB_OUTPUT
35+
echo "version_tag=${{ inputs.version_tag_prefix }}$version" >> $GITHUB_OUTPUT
36+
shell: bash
37+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#
2+
name: Update Version in Source Code
3+
4+
description: |
5+
Get the version from the source code and output the version and tag.
6+
7+
inputs:
8+
version:
9+
description: 'The version number (e.g. 1.2.3)'
10+
required: true
11+
version_tag:
12+
description: 'Optionally, can The version tag (e.g. v1.2.3)'
13+
version_file:
14+
description: 'The file containing the version number'
15+
default: '_version.py'
16+
required: false
17+
version_regex:
18+
description:|
19+
The regex to extract everything BUT the version number. It is very important to
20+
capture BEFORE and AFTER the version number. This is going to be used with `sed -E`
21+
default: "(__version__ = ['\"])[0-9]+\.[0-9]+\.[0-9]+(['\"])"
22+
required: false
23+
24+
runs:
25+
using: "composite"
26+
steps:
27+
- name: Update Version in Source Code
28+
run: |
29+
echo "Updating version to ${{ inputs.version }}"
30+
find . -name ${{ inputs.version_file }} -exec sed -i -E "s/${{ inputs.version_regex }}/\1${new_version}\2/" {} \;
31+
echo git diff following update:
32+
git diff
33+
- name: Create Git commit and tag
34+
if ! git diff --name-only -- **/${{ inputs.version_file }} | grep -q '${{ inputs.version_file }}'; then
35+
echo "No changes detected. Version already ${{ inputs.version }}."
36+
echo "Skipping commit and tag."
37+
else
38+
echo "Changes detected."
39+
git add **/${{ inputs.version_file }}
40+
git commit -m "Bump version to ${{ inputs.version }}"
41+
git push
42+
43+
if [ -z "${{ inputs.version_tag }}" ]; then
44+
echo "No version tag provided. Skipping tag."
45+
echo "Skipping tag."
46+
else
47+
echo "Creating tag ${{ inputs.version_tag }}"
48+
git tag -a ${{ inputs.version_tag }} -m "Release ${{ inputs.version_tag }}"
49+
git push --tags
50+
fi
51+
fi
52+
```

.github/workflows/build.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ name: Build and Test
33
on:
44
pull_request:
55
branches: [ main ]
6+
paths-ignore:
7+
- '**/_version.py'
68
push:
79
branches: [ main ]
10+
paths-ignore:
11+
- '**/_version.py'
812

913
jobs:
1014
test:
@@ -14,7 +18,7 @@ jobs:
1418
strategy:
1519
fail-fast: false
1620
matrix:
17-
python-version: ["3.9", "3.10", "3.11"]
21+
python-version: ["3.9", "3.10", "3.11", "3.12"]
1822
steps:
1923
- uses: actions/checkout@v4
2024
- name: Set up Python ${{ matrix.python-version }}
@@ -23,11 +27,11 @@ jobs:
2327
python-version: ${{ matrix.python-version }}
2428
cache: 'pip'
2529
- name: Set up AllenInstitute Repo Authorization
26-
uses: ./.github/actions/setup-ai-github-urls
30+
uses: ./.github/actions/configure-org-repo-authorization
2731
with:
2832
token: ${{ secrets.AI_PACKAGES_TOKEN }}
2933
ssh_private_key: ${{ secrets.AIBSGITHUB_PRIVATE_KEY }}
3034
- name: Run Release
31-
shell: bash
3235
run: |
3336
make release
37+
shell: bash

.github/workflows/bump_version.yml

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

0 commit comments

Comments
 (0)