Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: bump version and release automation v2 #328

Merged
merged 4 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ version-resolver:

exclude-labels:
- 'release:changelog'
- 'release:bump-version'
- 'skip'

template: |
Expand Down
174 changes: 87 additions & 87 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
@@ -1,91 +1,91 @@
name: 'Update the package version'
on:
pull_request:
types: [opened, reopened]
branches:
- main
jobs:
release_label:
name: Prepare version update
runs-on: ubuntu-latest
outputs:
version_type: ${{steps.version_label_check.outputs.is_version}}
steps:
- name: Set major release
id: version_label_check
run: |
echo "::set-output name=is_version::${{ github.event.label.name }}"
# name: 'Update the package version'
# on:
# pull_request:
# types: [opened, reopened]
# branches:
# - main
# jobs:
# release_label:
# name: Prepare version update
# runs-on: ubuntu-latest
# outputs:
# version_type: ${{steps.version_label_check.outputs.is_version}}
# steps:
# - name: Set major release
# id: version_label_check
# run: |
# echo "::set-output name=is_version::${{ github.event.label.name }}"

package_bump_scripts:
runs-on: ubuntu-latest
needs: release_label
steps:
- name: Checkout local repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Create release branch
run: |
git branch -f auto-release-branch
git checkout auto-release-branch
- name: Initialize mandatory git config
run: |
git config user.name "GitHub Actions"
git config user.email [email protected]

- name: Set major release
if: ${{ needs.release_label.outputs.version_type == 'major' }}
run: |
chmod +x ./scripts/incrementMajor.js
./scripts/incrementMajor.js
- name: Set minor release
if: ${{ needs.release_label.outputs.version_type == 'minor' }}
run: |
chmod +x ./scripts/incrementMinor.js
./scripts/incrementMinor.js
- name: Set patch release
if: ${{ needs.release_label.outputs.version_type == 'patch' || needs.release_label.outputs.version_type == '' }}
run: |
chmod +x ./scripts/incrementPatch.js
./scripts/incrementPatch.js
# package_bump_scripts:
# runs-on: ubuntu-latest
# needs: release_label
# steps:
# - name: Checkout local repository
# uses: actions/checkout@v3
# with:
# ref: ${{ github.head_ref }}
# - name: Create release branch
# run: |
# git branch -f auto-release-branch
# git checkout auto-release-branch
# - name: Initialize mandatory git config
# run: |
# git config user.name "GitHub Actions"
# git config user.email [email protected]

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'ci: automated version bump on merge to main'

- name: Push new branch
run: git push origin auto-release-branch --force
# - name: Set major release
# if: ${{ needs.release_label.outputs.version_type == 'major' }}
# run: |
# chmod +x ./scripts/incrementMajor.js
# ./scripts/incrementMajor.js
# - name: Set minor release
# if: ${{ needs.release_label.outputs.version_type == 'minor' }}
# run: |
# chmod +x ./scripts/incrementMinor.js
# ./scripts/incrementMinor.js
# - name: Set patch release
# if: ${{ needs.release_label.outputs.version_type == 'patch' || needs.release_label.outputs.version_type == '' }}
# run: |
# chmod +x ./scripts/incrementPatch.js
# ./scripts/incrementPatch.js

- name: Create pull request to develop
uses: thomaseizinger/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
head: auto-release-branch
base: develop
title: package version bump
reviewers: ${{ github.event.pull_request.user.login }}
body: |
## Reminder: delete after merge!!!
> # This PR was created in response workflow running.

- name: Find Pull Request
uses: juliangruber/find-pull-request-action@v1
id: find-pull-request
with:
branch: auto-release-branch
- run: echo "Pull Request ${number} (${sha})"
env:
number: ${{ steps.find-pull-request.outputs.number }}
sha: ${{ steps.find-pull-request.outputs.head-sha }}
# - uses: stefanzweifel/git-auto-commit-action@v4
# with:
# commit_message: 'ci: automated version bump on merge to main'

- name: Comment on PR
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "Merge pull request #${{ steps.find-pull-request.outputs.number }} first, before merging this!!"
})
# - name: Push new branch
# run: git push origin auto-release-branch --force

# - name: Create pull request to develop
# uses: thomaseizinger/[email protected]
# with:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# head: auto-release-branch
# base: develop
# title: package version bump
# reviewers: ${{ github.event.pull_request.user.login }}
# body: |
# ## Reminder: delete after merge!!!
# > # This PR was created in response workflow running.

# - name: Find Pull Request
# uses: juliangruber/find-pull-request-action@v1
# id: find-pull-request
# with:
# branch: auto-release-branch
# - run: echo "Pull Request ${number} (${sha})"
# env:
# number: ${{ steps.find-pull-request.outputs.number }}
# sha: ${{ steps.find-pull-request.outputs.head-sha }}

# - name: Comment on PR
# uses: actions/github-script@v3
# with:
# github-token: ${{secrets.GITHUB_TOKEN}}
# script: |
# github.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: "Merge pull request #${{ steps.find-pull-request.outputs.number }} first, before merging this!!"
# })
24 changes: 22 additions & 2 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,31 @@ permissions:
contents: read

jobs:
branch_validation:
runs-on: ubuntu-latest
outputs:
validate_branch: ${{steps.valid_branch.outputs.is_match}}
steps:
- name: Check branch validation
id: valid_branch
run: |
if [[ ${{ github.event.pull_request.head.ref }} =~ ^release/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "match=true" >> $GITHUB_OUTPUT
echo "::set-output name=is_match::true"
else
echo "This is not a release branch"
exit 1
fi
- name: Build
if: steps.valid_branch.outputs.match == 'true'
run: |
echo "Branch is a match - head: ${{ github.event.pull_request.head.ref}}, base: ${{github.event.pull_request.base.ref }}"
update_release_draft:
name: release-drafter
needs: branch_validation
runs-on: ubuntu-latest
# check pull request from develop to main
if: ${{github.event.pull_request.base.ref == 'main' && github.event.pull_request.head.ref == 'develop' }}
# check pull request from release/v*.*.* to main
if: ${{ github.event.pull_request.base.ref == 'main' && needs.branch_validation.outputs.validate_branch == 'true'}}
permissions:
contents: write # for release-drafter/release-drafter to create a github release
pull-requests: write # for release-drafter/release-drafter to add label to PR
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: 'Release: Bump Version | Automation'

on:
workflow_dispatch:
inputs:
release-type:
type: choice
description: Choose release type
options:
- major-release
- minor-release
- patch-release
default: minor-release
required: true

jobs:
increment_version:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Config git
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"

- name: Get release type
run: |
echo "Release type : ${{ github.event.inputs.release-type }}"

- name: Increment patch version
if: contains(github.event.inputs.release-type, 'patch-release')
run: npm version patch
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Increment minor version
if: contains(github.event.inputs.release-type, 'minor-release')
run: npm version minor
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Increment major version
if: contains(github.event.inputs.release-type, 'major-release')
run: npm version major
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Package version
run: |
version=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | tr -d '[[:space:]]')
echo "Package version: $version"
echo "PACKAGE_VERSION=$version" >> $GITHUB_ENV

- name: Create new release branch
run: |
echo "git checkout -b release/v$(cat package.json | jq -r .version)"

- name: Push new branch
run: echo "git push origin release/v${{ env.RELEASE_BRANCH }} --force"

- name: Create pull request
id: create_pull_request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: bump version ${{ env.PACKAGE_VERSION }}'
committer: GitHub <[email protected]>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
title: 'Release: ${{ github.event.inputs.release-type }} of v${{ env.PACKAGE_VERSION }} '
body: 'This is an automatic release pull request created by GitHub Actions'
branch: release/v${{ env.PACKAGE_VERSION }}
base: main
labels: |
release:bump-version
21 changes: 16 additions & 5 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,29 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Package version
run: |
version=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | tr -d '[[:space:]]')
echo "Package version: $version"
echo "PACKAGE_VERSION=$version" >> $GITHUB_ENV

- name: Update changelog
run: |
yarn add github-release-notes -D
export GREN_GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
yarn run overrideChangelog

- name: Create Pull Request
id: create_pull_request
uses: peter-evans/create-pull-request@v3
with:
commit-message: 'build: update changelog'
title: Update Changelog
body: Update changelog to reflect release changes
token: ${{ secrets.GITHUB_TOKEN }}
committer: GitHub <[email protected]>
commit-message: 'build: update changelog for v${{ env.PACKAGE_VERSION }}'
author: GitHub Action <[email protected]>
title: 'Update Changelog ${{ env.PACKAGE_VERSION }}'
body: 'Updated changelog for v${{ env.PACKAGE_VERSION }}, release changes refelct on ${{ github.event.repository.name }}'
branch: update-changelog
base: main
labels: release:changelog
base: develop
labels: |
release:changelog