-
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.
- Loading branch information
Showing
3 changed files
with
156 additions
and
3 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
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,6 @@ | ||
{ | ||
"cSpell.words": [ | ||
"elif", | ||
"releasetag" | ||
] | ||
} |
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,147 @@ | ||
name: "Release Composite Action" | ||
description: "P6 Action: Release a CDK Construct" | ||
author: "p6m7g8" | ||
inputs: | ||
aws_region: | ||
description: "AWS region for deployment" | ||
required: false | ||
default: "us-east-1" | ||
aws_role: | ||
description: "AWS role to assume" | ||
required: true | ||
aws_session_name: | ||
description: "Session name for the AWS role" | ||
required: true | ||
cdk_deploy_account: | ||
description: "AWS CDK deploy account" | ||
required: true | ||
cdk_deploy_region: | ||
description: "AWS CDK deploy region" | ||
required: true | ||
npm_token: | ||
description: "NPM token" | ||
required: true | ||
twine_username: | ||
description: "Twine username" | ||
required: true | ||
twine_password: | ||
description: "Twine password" | ||
required: true | ||
nuget_api_key: | ||
description: "Nugget API key" | ||
required: true | ||
go_github_token: | ||
description: "GoThub token" | ||
required: true | ||
p6_a_gh_token: | ||
description: "GitHub token" | ||
required: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Checkout code | ||
if: ${{ !contains(github.event.head_commit.message, 'chore(release):') }} | ||
uses: actions/checkout@v4.2.2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Bump Version | ||
id: bump | ||
if: ${{ !contains(github.event.head_commit.message, 'chore(release):') }} | ||
shell: bash | ||
run: | | ||
latest_tag=$(git tag --list "v*" --sort=-v:refname | head -1) | ||
log_lines=$(git log $latest_tag..HEAD --pretty="format:- %s") | ||
major=$(echo $latest_tag | cut -d. -f1) | ||
minor=$(echo $latest_tag | cut -d. -f2) | ||
patch=$(echo $latest_tag | cut -d. -f3) | ||
if echo "$log_lines" | grep -q "BREAKING CHANGE"; then | ||
major=$((major + 1)) | ||
minor=0 | ||
patch=0 | ||
elif echo "$log_lines" | grep -q "major"; then | ||
major=$((major + 1)) | ||
minor=0 | ||
patch=0 | ||
elif echo "$log_lines" | grep -q "feat"; then | ||
minor=$((minor + 1)) | ||
patch=0 | ||
elif echo "$log_lines" | grep -q "fix"; then | ||
patch=$((patch + 1)) | ||
elif echo "$log_lines" | grep -v "chore(release):" | grep -q "chore"; then | ||
patch=$((patch + 1)) | ||
else | ||
true | ||
fi | ||
new_tag="$major.$minor.$patch" | ||
npm version $new_tag --no-git-tag-version | ||
mkdir -p dist/ | ||
echo $new_tag >dist/releasetag.txt | ||
echo "$log_lines" | grep -v "chore(release):" >dist/changelog.md | ||
echo "Semantic version tag: $latest_tag -> $new_tag" | ||
echo "ChangeLog:" | ||
cat dist/changelog.md | ||
if grep -E "^- (chore|fix|feat|major)\!*" dist/changelog.md; then | ||
echo "bump=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "bump=false" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Github Release | ||
if: ${{ steps.bump.outputs.bump == 'true' }} | ||
shell: bash | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.p6_a_gh_token }} | ||
GITHUB_REPOSITORY: ${{ github.repository }} | ||
GITHUB_REF: ${{ github.ref }} | ||
run: | | ||
set -x | ||
tag_name=$(cat dist/releasetag.txt) | ||
if gh release view "$tag_nameE" -R "$GITHUB_REPOSITORY" > /dev/null 2>&1; then | ||
echo "Release with tag $tag_name already exists. Skipping release creation." | ||
else | ||
gh release create "$tag_name" -R "$GITHUB_REPOSITORY" -F dist/changelog.md -t "$tag_name" --target "$GITHUB_REF" | ||
echo "Release with tag $tag_name created successfully." | ||
fi | ||
- name: CDK Build | ||
if: ${{ steps.bump.outputs.bump == 'true' }} | ||
uses: p6m7g8-actions/cdk-construct-build@main | ||
with: | ||
aws_region: ${{ inputs.cdk_deploy_region }} | ||
aws_role: ${{ inputs.aws_role }} | ||
aws_session_name: ${{ inputs.aws_session_name }} | ||
cdk_deploy_account: ${{ inputs.cdk_deploy_account }} | ||
cdk_deploy_region: ${{ inputs.cdk_deploy_region }} | ||
- name: Publish to NPM | ||
if: ${{ steps.bump.outputs.bump == 'true' }} && contains(github.event.head_commit.message, 'chore(release):') | ||
shell: bash | ||
env: | ||
NPM_TOKEN: ${{ inputs.npm_token }} | ||
run: yarn run publish:npm | ||
- name: Publish to PYPI | ||
env: | ||
TWINE_USERNAME: ${{ inputs.twine_username }} | ||
TWINE_PASSWORD: ${{ inputs.twine_password }} | ||
if: ${{ steps.bump.outputs.bump == 'true' }} && contains(github.event.head_commit.message, 'chore(release):') | ||
shell: bash | ||
run: yarn run publish:pypi | ||
- name: Publish to Nuget | ||
env: | ||
NUGET_API_KEY: ${{ inputs.nuget_api_key }} | ||
if: ${{ steps.bump.outputs.bump == 'true' }} && contains(github.event.head_commit.message, 'chore(release):') | ||
shell: bash | ||
run: yarn run publish:nuget | ||
- name: Publish to GoLang | ||
if: ${{ steps.bump.outputs.bump == 'true' }} && contains(github.event.head_commit.message, 'chore(release):') | ||
shell: bash | ||
env: | ||
GIT_USER_NAME: ${{ github.actor }} | ||
GIT_USER_EMAIL: ${{ github.actor }}@users.noreply.github.com | ||
GH_TOKEN: ${{ inputs.go_github_token }} | ||
GITHUB_TOKEN: ${{ inputs.go_github_token }} | ||
run: | | ||
git config --global user.name "$GIT_USER_NAME" | ||
git config --global user.email "$GIT_USER_EMAIL" | ||
git remote set-url origin "https://$GH_TOKEN@github.com/$GITHUB_REPOSITORY.git" | ||
yarn run publish:golang |