feat(release): Bump release version #222
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
name: Create version branch & PR <working>/* -> version | |
on: | |
push: | |
branches: [ feature/*, bugfix/* ] | |
jobs: | |
auto-pr: | |
name: Automated Master Branch PR | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: write | |
packages: write | |
id-token: write | |
pull-requests: write | |
steps: | |
# Work around https://github.com/actions/checkout/issues/760 | |
- name: Add safe.directory | |
run: | | |
git config --global --add safe.directory /usr/lib/flutter | |
git config --global --add safe.directory /github/workspace | |
git config --global --add safe.directory $PWD | |
# ref.: https://github.com/actions/checkout, v3.5.0 | |
# NOTE: Fetch length must be 0 to recover all history for all branches and tags. | |
- name: Checkout repository | |
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 | |
with: | |
fetch-depth: 0 | |
- name: Extract branch name on pull request | |
shell: bash | |
run: | | |
set -x | |
git branch -r -l | |
echo "(current dir): $PWD" && ls -l ./ | |
chmod -Rv 555 ./scripts | |
RELEASE_VER=$(./scripts/version.sh) && echo "RELEASE_VER=$RELEASE_VER" >> $GITHUB_ENV | |
RELEASE_BRANCH="release/$RELEASE_VER" && echo "RELEASE_BRANCH=$RELEASE_BRANCH" >> $GITHUB_ENV | |
REPOSITORY_NAME="${{ github.event.repository.name }}" && echo "REPOSITORY_NAME=$REPOSITORY_NAME" >> $GITHUB_ENV | |
SOURCE_BRANCH="$(echo ${GITHUB_REF#refs/heads/})" | |
echo "SOURCE_BRANCH=$SOURCE_BRANCH" >> $GITHUB_ENV | |
echo "DEFAULT_BRANCH=${{ github.event.repository.default_branch }}" >> $GITHUB_ENV | |
echo "MASTER_REF=$(git ls-remote https://github.com/kiracore/$REPOSITORY_NAME | head -1 | sed 's/HEAD//')" >> $GITHUB_ENV | |
echo "LATEST_REF=$(git ls-remote https://github.com/kiracore/$REPOSITORY_NAME latest | awk '{ print $1}')" >> $GITHUB_ENV | |
echo "SOURCE_REF=$(echo $GITHUB_SHA)" >> $GITHUB_ENV | |
PARENT_BRANCH=$(git --no-pager log --decorate --simplify-by-decoration --oneline | grep -v "(HEAD" | head -n1 | sed 's/.* (\(.*\)) .*/\1/' | sed 's/\(.*\), .*/\1/' | sed 's/origin\///' | cut -d ',' -f 1 || echo "") | |
[ -z "$PARENT_BRANCH" ] && PARENT_BRANCH="master" | |
echo "PARENT_BRANCH=$PARENT_BRANCH" >> "$GITHUB_ENV" | |
echo "PARENT_BRANCH_REF=$(git ls-remote https://github.com/kiracore/$REPOSITORY_NAME $PARENT_BRANCH | awk '{ print $1}' | head -n1)" >> $GITHUB_ENV | |
[ -z "$PARENT_BRANCH_REF" ] && PARENT_BRANCH_REF="$MASTER_REF" && PARENT_BRANCH="master" | |
git ls-remote https://github.com/kiracore/$REPOSITORY_NAME | egrep -q "refs/tags/${RELEASE_VER}$" && echo "RELEASE_EXISTS=true" >> $GITHUB_ENV || echo "RELEASE_EXISTS=false" >> $GITHUB_ENV | |
( git show-branch "origin/$RELEASE_BRANCH" || git show-branch "remotes/origin/$RELEASE_BRANCH" ) && echo "TARGET_BRANCH_EXISTS=true" >> $GITHUB_ENV || echo "TARGET_BRANCH_EXISTS=false" >> $GITHUB_ENV | |
- name: Print debug data before publishing | |
run: | | |
echo "Repository name: ${{ env.REPOSITORY_NAME }}" | |
echo " Source branch: ${{ env.SOURCE_BRANCH }}" | |
echo " Default branch: ${{ env.DEFAULT_BRANCH }}" | |
echo " Parent branch: ${{ env.PARENT_BRANCH }}" | |
echo " Master refer.: ${{ env.MASTER_REF }}" | |
echo " Latest refer.: ${{ env.LATEST_REF }}" | |
echo " Source refer.: $GITHUB_SHA" | |
echo " Parent refer.: ${{ env.PARENT_BRANCH_REF }}" | |
echo "Release version: ${{ env.RELEASE_VER }}" | |
echo " Release branch: ${{ env.RELEASE_BRANCH }}" | |
echo " Release exists: ${{ env.RELEASE_EXISTS }}" | |
echo " Event name: ${{ github.event_name }}" | |
echo " Target Exists: ${{ env.TARGET_BRANCH_EXISTS }}" | |
# ref.: https://github.com/peterjgrainger/action-create-branch, v2.4.0 | |
- name: Create version branch from source | |
uses: peterjgrainger/action-create-branch@08259812c8ebdbf1973747f9297e332fa078d3c1 | |
if: | | |
( env.TARGET_BRANCH_EXISTS == false || env.TARGET_BRANCH_EXISTS == 'false' ) && | |
( env.RELEASE_EXISTS == false || env.RELEASE_EXISTS == 'false' ) && | |
( startsWith(env.RELEASE_BRANCH, 'release/v') && contains(env.RELEASE_BRANCH, '.') ) | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
branch: ${{ env.RELEASE_BRANCH }} | |
sha: ${{ env.PARENT_BRANCH_REF }} | |
# https://github.com/CodelyTV/no-pull-requests, v1 | |
- name: Close All PRs | |
if: ( env.RELEASE_EXISTS == false || env.RELEASE_EXISTS == 'false' ) && | |
( startsWith(env.RELEASE_BRANCH, 'release/v') && contains(env.RELEASE_BRANCH, '.') ) | |
uses: CodelyTV/no-pull-requests@53f1180ae5c5a7ccacdc55e03d5152ecfaeb1e00 | |
with: | |
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS }} | |
message: "This PR is obsolete, ${{env.SOURCE_BRANCH}} branch is ahead of your branch." | |
- name: Create PR from feature to version branch | |
# ref. repo-sync/pull-request is broken, using cea2aj/pull-request instead | |
uses: cea2aj/pull-request@84eb0c3478f13651e5649367941b867ca02d7926 | |
if: | | |
( env.RELEASE_EXISTS == false || env.RELEASE_EXISTS == 'false' ) && | |
( startsWith(env.RELEASE_BRANCH, 'release/v') && contains(env.RELEASE_BRANCH, '.') ) | |
with: | |
github_token: ${{ secrets.REPO_ACCESS }} | |
source_branch: ${{ env.SOURCE_BRANCH }} | |
destination_branch: ${{ env.RELEASE_BRANCH}} | |
pr_title: "${{ env.SOURCE_BRANCH }} -> ${{ env.RELEASE_BRANCH }}" | |
pr_label: "kira-automation" | |
pr_allow_empty: true |