Skip to content

ci: refactoring ci #382

ci: refactoring ci

ci: refactoring ci #382

Workflow file for this run

## Back-merging should typically be done as part of your Continuous Integration (CI) process
## By performing back-merging as part of the CI process, we can catch and fix any conflicts between the dev and main branches early in the development cycle, before the changes are deployed to production. This helps to ensure that the dev branch remains in a releasable state, and reduces the risk of integration issues when changes are eventually merged into the main branch.
# name: Back-Merge
#
#on:
# # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run
# # https://stackoverflow.com/questions/63343937/how-to-use-the-github-actions-workflow-run-event
# # https://blog.pother.ca/github-actions-workflow_run-event/
# # This event will only trigger a workflow run if the workflow file is on the default branch.
# # According documentation 'GITHUB_REF' for workflow_run always is default branch(develop), and for access original branch for workflow_run we can use 'github.event.workflow_run.head_branch'
# workflow_run:
# workflows:
# ["Catalogs-CI-CD", "Customers-CI-CD", "Identity-CI-CD", "Orders-CI-CD"]
# branches: [develop, main, preview, beta]
# types: [completed]
#
# pull_request:
# types: [closed] # when PR is merged, CD will be triggered
# branches:
# - develop
# - beta
# - preview
# - main
#
# workflow_dispatch:
# inputs:
# logLevel:
# description: "Log level"
# required: true
# default: "info"
# type: choice
# options:
# - info
# - warning
# - debug
#
#jobs:
# pre-check:
# runs-on: ubuntu-latest
#
# # Skipping workflow runs for some commits types
# # https://itnext.io/automate-your-integration-tests-and-semantic-releases-with-github-actions-43875ad83092
# # https://github.com/actions/runner/issues/491#issuecomment-850884422
# # https://stackoverflow.com/questions/69354003/github-action-job-fire-when-previous-job-skipped
# # we should not filter on head commit message types like 'chore', 'docs' because it is possible it our latest SHA commit in integration branches like develop and main be these types and it will skips whole of our trigger
# if: |
# github.actor != 'dependabot[bot]'
#
# steps:
# - name: Job Info
# run: |
# echo "pre-check is successful."
# echo workspace is: ${{ github.workspace }}
# echo "is workflow_dispatch event? ${{ github.event_name == 'workflow_dispatch' }}"
# echo "is push event? ${{ github.event_name == 'push' }}"
# echo "is pull request event? ${{ github.event_name == 'pull_request' }}"
# echo "pull_request.head.ref is: ${{ github.event.pull_request.head.ref }}"
# echo "github.ref_name is: ${{ github.ref_name }}"
# echo "github.ref is: ${{ github.ref }}"
# echo "github.head_ref is: ${{ github.head_ref }}"
# echo "should publish in dispatch mode? ${{ github.event.inputs.should-publish }}"
#
# back-merge:
# runs-on: ubuntu-latest
# needs: [pre-check]
#
# if: |
# success() &&
# github.event_name != 'pull_request' &&
# ((github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && contains(fromJson('["develop", "main", "preview", "beta"]'), github.event.workflow_run.head_branch)) || (github.event_name == 'workflow_dispatch' && contains(fromJson('["develop", "main", "preview", "beta"]'), github.ref_name)))
#
# permissions:
# pull-requests: write
#
# steps:
# - name: Set branch name as env variable
# shell: bash
# run: |
# if [ ${{ github.event_name }} = 'workflow_run' ]; then
# echo "BRANCH=${{ github.event.workflow_run.head_branch }}" >> $GITHUB_ENV
# else
# echo "BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV
# fi
#
# # https://github.com/cycjimmy/semantic-release-action/issues/6
# # https://github.com/actions/checkout#push-a-commit-using-the-built-in-token
# # https://stackoverflow.com/questions/750172/how-do-i-change-the-author-and-committer-name-email-for-multiple-commits
# # https://github.com/semantic-release/semantic-release/issues/1208
# # https://github.com/orgs/community/discussions/26560
# # https://blog.pother.ca/github-actions-workflow_run-event/
# # https://stackoverflow.com/questions/63343937/how-to-use-the-github-actions-workflow-run-event
# # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run
# # https://github.com/semantic-release/semantic-release/blob/b9b5c7689f0acdfdc079c839db0fcf78339745e2/index.js#L92
# ## https://github.com/actions/checkout/issues/439#issuecomment-965968956
# # get latest remote change because sematic-release in `verifyConditions` event checks local branch has latest remote branch changes, for preventing: The local branch `something` is behind the remote one, therefore a new version won't be published.
# # By default checkout@v3, will check branch on ref/SHA that triggered in starting workflow, so if inner a job in the workflow we change HEAD of repository by changing code, subsequent jobs don't get these commits and they get ref/SHA that triggered in starting workflow
# # we can't create a `composite-action` for `checkout` because for finding composite-action locally with relative path, repository should be `checkout` first
# - name: Check out code
# uses: actions/checkout@v3
# with:
# # https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
# # Only a single commit is fetched by default, for the ref/SHA that triggered the workflow. Set fetch-depth: 0 to fetch all history for all branches and tags
# fetch-depth: 0
# repository: ${{ github.repository }}
# token: ${{ secrets.GITHUB_TOKEN }}
# # set ref to 'github.ref' works correctly with both pull_requests event and push event and this is default behavior checkout action when we don't use ref attribute
# ref: ${{ github.ref }}
# - run: |
# git config user.name 'github-actions[bot]'
# git config user.email 'github-actions[bot]@users.noreply.github.com'
# shell: bash
#
# - name: Call Composite Action back-merge
# uses: ./.github/actions/back-merge
# id: back-merge-step
# with:
# source-branch: ${{ env.BRANCH }}
#
# back-merge-pr-closed:
# runs-on: ubuntu-latest
# needs: [pre-check]
#
# permissions:
# contents: write # for back-merging feature branch
#
# if: |
# success() &&
# (github.event_name == 'pull_request' && github.event.pull_request.merged == true && contains(fromJson('["develop", "preview", "beta"]'), github.ref_name))
#
# steps:
# - name: Set branch name as env variable
# shell: bash
# run: |
# if [ ${{ github.event_name }} = 'workflow_run' ]; then
# echo "BRANCH=${{ github.event.workflow_run.head_branch }}" >> $GITHUB_ENV
# else
# echo "BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV
# fi
#
# # https://github.com/cycjimmy/semantic-release-action/issues/6
# # https://github.com/actions/checkout#push-a-commit-using-the-built-in-token
# # https://stackoverflow.com/questions/750172/how-do-i-change-the-author-and-committer-name-email-for-multiple-commits
# # https://github.com/semantic-release/semantic-release/issues/1208
# # https://github.com/orgs/community/discussions/26560
# # https://blog.pother.ca/github-actions-workflow_run-event/
# # https://stackoverflow.com/questions/63343937/how-to-use-the-github-actions-workflow-run-event
# # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run
# # https://github.com/semantic-release/semantic-release/blob/b9b5c7689f0acdfdc079c839db0fcf78339745e2/index.js#L92
# ## https://github.com/actions/checkout/issues/439#issuecomment-965968956
# # get latest remote change because sematic-release in `verifyConditions` event checks local branch has latest remote branch changes, for preventing: The local branch `something` is behind the remote one, therefore a new version won't be published.
# # By default checkout@v3, will check branch on ref/SHA that triggered in starting workflow, so if inner a job in the workflow we change HEAD of repository by changing code, subsequent jobs don't get these commits and they get ref/SHA that triggered in starting workflow
# # we can't create a `composite-action` for `checkout` because for finding composite-action locally with relative path, repository should be `checkout` first
# - name: Check out code
# uses: actions/checkout@v3
# with:
# # https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
# # Only a single commit is fetched by default, for the ref/SHA that triggered the workflow. Set fetch-depth: 0 to fetch all history for all branches and tags
# fetch-depth: 0
# repository: ${{ github.repository }}
# token: ${{ secrets.GITHUB_TOKEN }}
# # set ref to 'github.ref' works correctly with both pull_requests event and push event and this is default behavior checkout action when we don't use ref attribute
# ref: ${{ github.ref }}
# - run: |
# git config user.name 'github-actions[bot]'
# git config user.email 'github-actions[bot]@users.noreply.github.com'
# shell: bash
#
# # https://stackoverflow.com/questions/69839851/github-actions-copy-git-user-name-and-user-email-from-last-commit
# # https://github.com/orgs/community/discussions/26560
# # https://github.com/semantic-release/semantic-release/discussions/2557
# # https://github.com/semantic-release/github/issues/175
# # this needs a PAT with write permission without doing pull request
# - name: Back Merge Feature Branches
# shell: bash
# run: |
# ./back-merge.sh ${{ github.ref_name }}