Skip to content

Commit

Permalink
Merge pull request #37 from passageidentity/PSG-5060
Browse files Browse the repository at this point in the history
PSG-5060
  • Loading branch information
SinaSeylani authored Oct 18, 2024
2 parents 355136a + 2e7a6fe commit 9765611
Show file tree
Hide file tree
Showing 3 changed files with 406 additions and 1 deletion.
379 changes: 379 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,379 @@
name: Create Release

on:
workflow_dispatch:
inputs:
release-type:
required: true
type: choice
description: What type of release
options:
- major
- minor
- patch

jobs:
determine-next-versions:
name: Determine Next Version
runs-on: ubuntu-latest

outputs:
next-major: ${{ steps.nexttag.outputs.major }}
next-minor: ${{ steps.nexttag.outputs.minor }}
next-patch: ${{ steps.nexttag.outputs.patch }}
branch-major: ${{ steps.branchnames.outputs.major-branch }}
branch-minor: ${{ steps.branchnames.outputs.minor-branch }}
branch-patch: ${{ steps.branchnames.outputs.patch-branch }}
previous-tag: ${{ steps.getprevioustag.outputs.previous-tag }}

steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 0
tags: true

- name: Get Previous Tag
id: getprevioustag
run: |
previous_tag=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "Previous Tag: $previous_tag"
echo "previous_tag=$previous_tag" >> $GITHUB_ENV
echo "::set-output name=previous-tag::$previous_tag"
- name: Get Next Versions
id: nexttag
uses: "WyriHaximus/github-action-next-semvers@v1"
with:
version: ${{ steps.getprevioustag.outputs.previous-tag }}

- name: Build Branch Names
id: branchnames
run: |
echo "major-branch=release-major-v${{ steps.nexttag.outputs.major }}" >> $GITHUB_OUTPUT
echo "minor-branch=release-minor-v${{ steps.nexttag.outputs.minor }}" >> $GITHUB_OUTPUT
echo "patch-branch=release-patch-v${{ steps.nexttag.outputs.patch }}" >> $GITHUB_OUTPUT
create-release-branch:
name: Create Release Branch
runs-on: ubuntu-latest
needs: determine-next-versions

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Create major release branch
if: ${{ github.event.inputs.release-type == 'major' }}
run: |
git checkout -b ${{ needs.determine-next-versions.outputs.branch-major }}
git push origin ${{ needs.determine-next-versions.outputs.branch-major }}
- name: Create minor release branch
if: ${{ github.event.inputs.release-type == 'minor' }}
run: |
git checkout -b ${{ needs.determine-next-versions.outputs.branch-minor }}
git push origin ${{ needs.determine-next-versions.outputs.branch-minor }}
- name: Create patch release branch
if: ${{ github.event.inputs.release-type == 'patch' }}
run: |
git checkout -b ${{ needs.determine-next-versions.outputs.branch-patch }}
git push origin ${{ needs.determine-next-versions.outputs.branch-patch }}
create-change-file:
name: Generate Change File
runs-on: ubuntu-latest
needs: create-release-branch

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Generate Change File for Major Release
if: ${{ github.event.inputs.release-type == 'major' }}
run: |
mkdir -p .changes
echo '{
"packageName": "@your-package/react-native",
"type": "major",
"comment": "Automated major version bump"
}' > .changes/$(uuidgen).json
- name: Generate Change File for Minor Release
if: ${{ github.event.inputs.release-type == 'minor' }}
run: |
mkdir -p .changes
echo '{
"packageName": "@your-package/react-native",
"type": "minor",
"comment": "Automated minor version bump"
}' > .changes/$(uuidgen).json
- name: Generate Change File for Patch Release
if: ${{ github.event.inputs.release-type == 'patch' }}
run: |
mkdir -p .changes
echo '{
"packageName": "@your-package/react-native",
"type": "patch",
"comment": "Automated patch version bump"
}' > .changes/$(uuidgen).json
- name: Commit Change File for Major Release
if: ${{ github.event.inputs.release-type == 'major' }}
run: |
git add .changes/
git commit -m "chore: add changefile for major release"
git push origin ${{ needs.determine-next-versions.outputs.branch-major }}
- name: Commit Change File for Minor Release
if: ${{ github.event.inputs.release-type == 'minor' }}
run: |
git add .changes/
git commit -m "chore: add changefile for minor release"
git push origin ${{ needs.determine-next-versions.outputs.branch-minor }}
- name: Commit Change File for Patch Release
if: ${{ github.event.inputs.release-type == 'patch' }}
run: |
git add .changes/
git commit -m "chore: add changefile for patch release"
git push origin ${{ needs.determine-next-versions.outputs.branch-patch }}
- name: Beachball Check
run: npm run beachball:check

- name: Beachball Bump
run: npm run beachball:bump

bump-version:
name: Bump the Version
runs-on: ubuntu-latest
needs: [determine-next-versions, create-release-branch, create-change-file]

steps:
- name: Check out code - major release
if: ${{ github.event.inputs.release-type == 'major' }}
uses: actions/checkout@v3
with:
ref: ${{ needs.determine-next-versions.outputs.branch-major }}

- name: Check out code - minor release
if: ${{ github.event.inputs.release-type == 'minor' }}
uses: actions/checkout@v3
with:
ref: ${{ needs.determine-next-versions.outputs.branch-minor }}

- name: Check out code - patch release
if: ${{ github.event.inputs.release-type == 'patch' }}
uses: actions/checkout@v3
with:
ref: ${{ needs.determine-next-versions.outputs.branch-patch }}

- name: Update major version in package.json
if: ${{ github.event.inputs.release-type == 'major' }}
run: |
new_version=${{ needs.determine-next-versions.outputs.next-major }}
jq --arg new_version "$new_version" '.version = $new_version' package.json > package.tmp.json && mv package.tmp.json package.json
echo "Updated to version $new_version"
- name: Update minor version in package.json
if: ${{ github.event.inputs.release-type == 'minor' }}
run: |
new_version=${{ needs.determine-next-versions.outputs.next-minor }}
jq --arg new_version "$new_version" '.version = $new_version' package.json > package.tmp.json && mv package.tmp.json package.json
echo "Updated to version $new_version"
- name: Update patch version in package.json
if: ${{ github.event.inputs.release-type == 'patch' }}
run: |
new_version=${{ needs.determine-next-versions.outputs.next-patch }}
jq --arg new_version "$new_version" '.version = $new_version' package.json > package.tmp.json && mv package.tmp.json package.json
echo "Updated to version $new_version"
- name: Install dependencies and update package-lock.json
run: npm install

- name: Prepend to CHANGELOG.md - major release
if: ${{ github.event.inputs.release-type == 'major' }}
run: |
new_version=${{ needs.determine-next-versions.outputs.next-major }}
previous_tag=${{ needs.determine-next-versions.outputs.previous-tag }}
git fetch --tags
git fetch --all
release_notes=$(git log --pretty=format:"* %s" $previous_tag..HEAD)
echo "Release Notes: $release_notes"
echo -e "## $new_version\n\n$release_notes\n\n$(cat CHANGELOG.md)" > CHANGELOG.md
echo "Prepended CHANGELOG.md with version $new_version"
- name: Prepend to CHANGELOG.md - minor release
if: ${{ github.event.inputs.release-type == 'minor' }}
run: |
new_version=${{ needs.determine-next-versions.outputs.next-minor }}
previous_tag=${{ needs.determine-next-versions.outputs.previous-tag }}
git fetch --tags
git fetch --all
release_notes=$(git log --pretty=format:"* %s" $previous_tag..HEAD)
echo "Release Notes: $release_notes"
echo -e "## $new_version\n\n$release_notes\n\n$(cat CHANGELOG.md)" > CHANGELOG.md
echo "Prepended CHANGELOG.md with version $new_version"
- name: Prepend to CHANGELOG.md - patch release
if: ${{ github.event.inputs.release-type == 'patch' }}
run: |
new_version=${{ needs.determine-next-versions.outputs.next-patch }}
previous_tag=${{ needs.determine-next-versions.outputs.previous-tag }}
git fetch --tags
git fetch --all
release_notes=$(git log --pretty=format:"* %s" $previous_tag..HEAD)
echo "Release Notes: $release_notes"
echo -e "## $new_version\n\n$release_notes\n\n$(cat CHANGELOG.md)" > CHANGELOG.md
echo "Prepended CHANGELOG.md with version $new_version"
- name: Commit major version change
if: ${{ github.event.inputs.release-type == 'major' }}
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Bumped version to ${{ needs.determine-next-versions.outputs.next-major }}"
branch: ${{ needs.determine-next-versions.outputs.branch-major }}

- name: Commit minor version change
if: ${{ github.event.inputs.release-type == 'minor' }}
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Bumped version to ${{ needs.determine-next-versions.outputs.next-minor }}"
branch: ${{ needs.determine-next-versions.outputs.branch-minor }}

- name: Commit patch version change
if: ${{ github.event.inputs.release-type == 'patch' }}
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Bumped version to ${{ needs.determine-next-versions.outputs.next-patch }}"
branch: ${{ needs.determine-next-versions.outputs.branch-patch }}

create-github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [determine-next-versions, create-release-branch, bump-version]

steps:
- name: Create Release - major
if: ${{ github.event.inputs.release-type == 'major' }}
uses: ncipollo/release-action@v1
with:
tag: "v${{ needs.determine-next-versions.outputs.next-major }}"
generateReleaseNotes: true
draft: false

- name: Create Release - minor
if: ${{ github.event.inputs.release-type == 'minor' }}
uses: ncipollo/release-action@v1
with:
tag: "v${{ needs.determine-next-versions.outputs.next-minor }}"
generateReleaseNotes: true
draft: false

- name: Create Release - patch
if: ${{ github.event.inputs.release-type == 'patch' }}
uses: ncipollo/release-action@v1
with:
tag: "v${{ needs.determine-next-versions.outputs.next-patch }}"
generateReleaseNotes: true
draft: false

create-pull-request:
name: Create Pull Request
runs-on: ubuntu-latest
needs: [ create-github-release, determine-next-versions ]

steps:
- name: Check out code - major release
if: ${{ github.event.inputs.release-type == 'major' }}
uses: actions/checkout@v3
with:
ref: ${{ needs.determine-next-versions.outputs.branch-major }}

- name: Check out code - minor release
if: ${{ github.event.inputs.release-type == 'minor' }}
uses: actions/checkout@v3
with:
ref: ${{ needs.determine-next-versions.outputs.branch-minor }}

- name: Check out code - patch release
if: ${{ github.event.inputs.release-type == 'patch' }}
uses: actions/checkout@v3
with:
ref: ${{ needs.determine-next-versions.outputs.branch-patch }}

- name: Create pull request for major release into main
if: ${{ github.event.inputs.release-type == 'major' }}
uses: thomaseizinger/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
head: ${{needs.determine-next-versions.outputs.branch-major}}
base: main
title: v${{ needs.determine-next-versions.outputs.next-major }} into main
body: |
This PR was created by the create-release-branch workflow.
New Release: v${{ needs.determine-next-versions.outputs.next-major }}
I've updated the version name and code commit.
- name: Create pull request for minor release into main
if: ${{ github.event.inputs.release-type == 'minor' }}
uses: thomaseizinger/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
head: ${{needs.determine-next-versions.outputs.branch-minor}}
base: main
title: v${{ needs.determine-next-versions.outputs.next-minor }} into main
body: |
This PR was created by the create-release-branch workflow.
New Release: v${{ needs.determine-next-versions.outputs.next-minor }}
I've updated the version name and code commit.
- name: Create pull request for patch release into main
if: ${{ github.event.inputs.release-type == 'patch' }}
uses: thomaseizinger/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
head: ${{needs.determine-next-versions.outputs.branch-patch}}
base: main
title: v${{ needs.determine-next-versions.outputs.next-patch }} into main
body: |
This PR was created by the create-release-branch workflow.
New Release: v${{ needs.determine-next-versions.outputs.next-patch }}
I've updated the version name and code commit.
publish-sdk:
name: Publish SDK
runs-on: ubuntu-latest
needs: [ create-github-release, determine-next-versions ]

steps:
- name: Trigger publish workflow - major
if: ${{ github.event.inputs.release-type == 'major' }}
run: |
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/dispatches \
-d '{"event_type":"publish", "client_payload": {"ref": "${{needs.determine-next-versions.outputs.branch-major}}"}}'
- name: Trigger publish workflow - minor
if: ${{ github.event.inputs.release-type == 'minor' }}
run: |
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/dispatches \
-d '{"event_type":"publish", "client_payload": {"ref": "${{needs.determine-next-versions.outputs.branch-minor}}"}}'
- name: Trigger publish workflow - patch
if: ${{ github.event.inputs.release-type == 'patch' }}
run: |
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/dispatches \
-d '{"event_type":"publish", "client_payload": {"ref": "${{needs.determine-next-versions.outputs.branch-patch}}"}}'
Loading

0 comments on commit 9765611

Please sign in to comment.