-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from AllenInstitute/feature/misc-stuff
Add new GH actions, new lambda functions, core/auth updates, version changes
- Loading branch information
Showing
13 changed files
with
466 additions
and
20 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
name: Bump Version and Tag Reusable Workflow | ||
|
||
description: | | ||
Get the would-be bumped version and version tag for a commit based on the | ||
changes since last version. | ||
inputs: | ||
bump_type: | ||
description: 'Version Bump Type' | ||
type: choice | ||
options: ['major', 'minor', 'patch', 'none'] | ||
required: false | ||
default: 'none' | ||
dry_run: | ||
description: 'Dry Run' | ||
type: boolean | ||
required: false | ||
default: false | ||
token: | ||
description: 'Token for AllenInstitute GitHub' | ||
required: true | ||
outputs: | ||
major: | ||
description: 'The major version number' | ||
value: ${{ steps.set-outputs.outputs.major }} | ||
minor: | ||
description: 'The minor version number' | ||
value: ${{ steps.set-outputs.outputs.minor }} | ||
patch: | ||
description: 'The patch version number' | ||
value: ${{ steps.set-outputs.outputs.patch }} | ||
increment: | ||
description: 'The increment. This is the number of commits since the last tag.' | ||
value: ${{ steps.set-outputs.outputs.increment }} | ||
version: | ||
description: 'The version number (e.g. 1.2.3)' | ||
value: ${{ steps.set-outputs.outputs.version }} | ||
version_tag: | ||
description: 'The version tag (e.g. v1.2.3)' | ||
value: ${{ steps.set-outputs.outputs.version_tag }} | ||
version_type: | ||
description: 'The version type (e.g. major, minor, patch, none)' | ||
value: ${{ steps.set-outputs.outputs.version_type }} | ||
previous_version: | ||
description: 'The previous version number (e.g. 1.2.2)' | ||
value: ${{ steps.set-outputs.outputs.previous_version }} | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Bump patch version and tag | ||
id: bump-version-tag | ||
uses: anothrNick/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.token }} | ||
DEFAULT_BUMP: ${{ inputs.bump_type || 'none' }} | ||
MAJOR_STRING_TOKEN: '(MAJOR)' | ||
MINOR_STRING_TOKEN: '(MINOR)' | ||
PATCH_STRING_TOKEN: '(PATCH)' | ||
NONE_STRING_TOKEN: '(NONE)' | ||
WITH_V: "true" | ||
RELEASE_BRANCHES: main | ||
DRY_RUN: true | ||
- name: Set Outputs | ||
id: set-outputs | ||
run: | | ||
new_tag=${{ steps.bump-version-tag.outputs.new_tag }} | ||
new_version=$(echo $new_tag | sed 's/^v//') | ||
major=$(echo $new_version | cut -d. -f1) | ||
minor=$(echo $new_version | cut -d. -f2) | ||
patch=$(echo $new_version | cut -d. -f3) | ||
increment=0 | ||
version_type=${{ steps.bump-version-tag.outputs.part }} | ||
previous_version=$(git describe --tags --abbrev=0 | sed 's/^v//') | ||
echo "major=$major" >> $GITHUB_OUTPUT | ||
echo "minor=$minor" >> $GITHUB_OUTPUT | ||
echo "patch=$patch" >> $GITHUB_OUTPUT | ||
echo "increment=$increment" >> $GITHUB_OUTPUT | ||
echo "version=$new_version" >> $GITHUB_OUTPUT | ||
echo "version_tag=$new_tag" >> $GITHUB_OUTPUT | ||
echo "version_type=$version_type" >> $GITHUB_OUTPUT | ||
echo "previous_version=$previous_version" >> $GITHUB_OUTPUT | ||
shell: bash | ||
|
||
# Currently not using this Version bumping tool, but considering it for the future. | ||
# The main limitation is being able to override the default bump type even | ||
# if there are no commits. | ||
- name: Bump Version Alternate | ||
uses: PaulHatch/[email protected] | ||
id: bump-version-tag-alt | ||
with: | ||
major_pattern: "/\\((MAJOR|BREAKING)\\)/" | ||
minor_pattern: "/\\((MINOR|FEATURE)\\)/" | ||
bump_each_commit: true | ||
bump_each_commit_patch_pattern: "/\\((PATCH|BUG)\\)/" | ||
- name: Set Outputs Alt | ||
id: set-outputs-alt | ||
shell: bash | ||
run: | | ||
echo 'changed: ${{ steps.bump-version-tag-alt.outputs.changed }}' | ||
echo 'major: ${{ steps.bump-version-tag-alt.outputs.major }}' | ||
echo 'minor: ${{ steps.bump-version-tag-alt.outputs.minor }}' | ||
echo 'patch: ${{ steps.bump-version-tag-alt.outputs.patch }}' | ||
echo 'increment: ${{ steps.bump-version-tag-alt.outputs.increment }}' | ||
echo 'version: ${{ steps.bump-version-tag-alt.outputs.version }}' | ||
echo 'version_tag: ${{ steps.bump-version-tag-alt.outputs.version_tag }}' | ||
echo 'version_type: ${{ steps.bump-version-tag-alt.outputs.version_type }}' | ||
echo 'previous_version: ${{ steps.bump-version-tag-alt.outputs.previous_version }}' | ||
# echo "major=${{ steps.bump-version-tag-alt.outputs.major }}" >> $GITHUB_OUTPUT | ||
# echo "minor=${{ steps.bump-version-tag-alt.outputs.minor }}" >> $GITHUB_OUTPUT | ||
# echo "patch=${{ steps.bump-version-tag-alt.outputs.patch }}" >> $GITHUB_OUTPUT | ||
# echo "increment=${{ steps.bump-version-tag-alt.outputs.increment }}" >> $GITHUB_OUTPUT | ||
# echo "version=${{ steps.bump-version-tag-alt.outputs.version }}" >> $GITHUB_OUTPUT | ||
# echo "version_tag=${{ steps.bump-version-tag-alt.outputs.version_tag }}" >> $GITHUB_OUTPUT | ||
# echo "version_type=${{ steps.bump-version-tag-alt.outputs.version_type }}" >> $GITHUB_OUTPUT | ||
# echo "previous_version=${{ steps.bump-version-tag-alt.outputs.previous_version }}" >> $GITHUB_OUTPUT |
2 changes: 1 addition & 1 deletion
2
...b/actions/setup-ai-github-urls/action.yml → ...nfigure-org-repo-authorization/action.yml
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# | ||
name: Get Version from Source Code | ||
|
||
description: | | ||
Get the version from the source code and output the version and tag. | ||
inputs: | ||
version_file: | ||
description: 'The file containing the version number' | ||
default: '_version.py' | ||
required: false | ||
version_regex: | ||
description: 'The regex to extract the version number' | ||
default: "__version__ = (?:\"|')([0-9]+\.[0-9]+\.[0-9]+)(?:\"|')" | ||
required: false | ||
version_tag_prefix: | ||
description: 'The prefix for the version tag' | ||
required: false | ||
default: 'v' | ||
outputs: | ||
version: | ||
description: 'The version number (e.g. 1.2.3)' | ||
version_tag: | ||
description: 'The version tag (e.g. v1.2.3)' | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Get Version | ||
id: get-version | ||
run: | | ||
version=$(find . -name ${{ inputs.version_file }} -exec cat {} \; | grep -oP -m 1 "${{ inputs.version_regex }}") | ||
echo "Version: $version" | ||
echo "version=$version" >> $GITHUB_OUTPUT | ||
echo "version_tag=${{ inputs.version_tag_prefix }}$version" >> $GITHUB_OUTPUT | ||
shell: bash | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# | ||
name: Update Version in Source Code | ||
|
||
description: | | ||
Get the version from the source code and output the version and tag. | ||
inputs: | ||
version: | ||
description: 'The version number (e.g. 1.2.3)' | ||
required: true | ||
version_tag: | ||
description: 'Optionally, can The version tag (e.g. v1.2.3)' | ||
version_file: | ||
description: 'The file containing the version number' | ||
default: '_version.py' | ||
required: false | ||
version_regex: | ||
description:| | ||
The regex to extract everything BUT the version number. It is very important to | ||
capture BEFORE and AFTER the version number. This is going to be used with `sed -E` | ||
default: "(__version__ = ['\"])[0-9]+\.[0-9]+\.[0-9]+(['\"])" | ||
required: false | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Update Version in Source Code | ||
run: | | ||
echo "Updating version to ${{ inputs.version }}" | ||
find . -name ${{ inputs.version_file }} -exec sed -i -E "s/${{ inputs.version_regex }}/\1${new_version}\2/" {} \; | ||
echo git diff following update: | ||
git diff | ||
- name: Create Git commit and tag | ||
if ! git diff --name-only -- **/${{ inputs.version_file }} | grep -q '${{ inputs.version_file }}'; then | ||
echo "No changes detected. Version already ${{ inputs.version }}." | ||
echo "Skipping commit and tag." | ||
else | ||
echo "Changes detected." | ||
git add **/${{ inputs.version_file }} | ||
git commit -m "Bump version to ${{ inputs.version }}" | ||
git push | ||
|
||
if [ -z "${{ inputs.version_tag }}" ]; then | ||
echo "No version tag provided. Skipping tag." | ||
echo "Skipping tag." | ||
else | ||
echo "Creating tag ${{ inputs.version_tag }}" | ||
git tag -a ${{ inputs.version_tag }} -m "Release ${{ inputs.version_tag }}" | ||
git push --tags | ||
fi | ||
fi | ||
``` |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
Oops, something went wrong.