Skip to content

Commit

Permalink
Merge pull request #127 from KiraCore/feature/ci-cd-v2
Browse files Browse the repository at this point in the history
feature/ci-cd-v2 -> release/v0.2.18
  • Loading branch information
asmodat authored Aug 10, 2022
2 parents 70de3e3 + 04e7eb4 commit 65e7641
Show file tree
Hide file tree
Showing 102 changed files with 27,104 additions and 2,015 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Create version branch & PR <working>/* -> version

on:
push:
branches: [ feature/*, bugfix/* ]

jobs:
auto-pr:
name: Automated Master Branch PR
runs-on: ubuntu-20.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.0.0
# NOTE: Fetch length must be 0 to recover all history for all branches and tags.
- name: Checkout repository
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
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.2.0
- name: Create version branch from source
uses: peterjgrainger/action-create-branch@c2800a3a9edbba2218da6861fa46496cf8f3195a
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 }}
- 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.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, '.') )
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
Loading

0 comments on commit 65e7641

Please sign in to comment.