Skip to content

Feature Branch CI -- Start Action - feature/IAT-300-Testing-5 #25

Feature Branch CI -- Start Action - feature/IAT-300-Testing-5

Feature Branch CI -- Start Action - feature/IAT-300-Testing-5 #25

name: Feature Branch Pipeline
run-name: "Feature Branch CI -- ${{github.event.inputs.action}} Action - feature/${{github.event.inputs.feature_branch}} "
on:
workflow_dispatch:
inputs:
action:
type: choice
description: Action
options:
- Start
- Finish
required: true
feature_branch:
type: string
description: Enter Branch Name (Without feature/ prefix)
required: true
env:
TRUNK_BRANCH: main
FEATURE_BRANCH: feature/${{github.event.inputs.feature_branch}}
jobs:
list_ps:
runs-on: ubuntu-latest
steps:
- name : Get Pull Requests
id: getPRList
uses: OmOmofonmwan/get-pr-number-based-off-branch-name@main
with:
github_token: ${{secrets.GITHUB_TOKEN}}
repository: ${{github.repository}}
branch_name: ${{env.FEATURE_BRANCH}}
- run: |
echo ${{steps.getPRList.outputs.pr_number}}
echo ${{steps.getPRList.outputs.pr_exists}}
exit 1
start_action:
needs: list_ps
runs-on: ubuntu-latest
name: Start Action - feature/${{github.event.inputs.feature_branch}}
if: github.event.inputs.action == 'Start' && github.event.inputs.feature_branch != ''
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4
- name: Downloading Java
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Get Current Version
run: |
echo "POM_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
- name: Print Version
run: echo ${{env.POM_VERSION}}
- name: Split version code
uses: xom9ikk/split@v1
id: splitVersion
with:
string: ${{env.POM_VERSION}}
separator: -SNAPSHOT
limit: -1
- name: Set New Unique Version
run: echo "uniqueVersion=${{steps.splitVersion.outputs._0}}-${{github.event.inputs.feature_branch}}-SNAPSHOT" >> $GITHUB_ENV
- name: Commit & Push
run: |
git config user.name fda_shield_omoruyi
git config user.email [email protected]
git pull -p
git checkout -b $FEATURE_BRANCH
mvn versions:set -DnewVersion=${{env.uniqueVersion}} -DgenerateBackupPoms=false
git commit -am "Draft: Update feature version to ${{env.uniqueVersion}}"
git push -u origin $FEATURE_BRANCH
- name: Run the Action
uses: devops-infra/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_branch: ${{env.FEATURE_BRANCH}}
target_branch: ${{env.TRUNK_BRANCH}}
title: Draft - ${{env.FEATURE_BRANCH}}
body: "**Currently work in progress - ${{env.FEATURE_BRANCH}}**"
draft: true
finish_action:
runs-on: ubuntu-latest
name: Finish Action - feature/${{github.event.inputs.feature_branch}}
if: github.event.inputs.action == 'Finish' && github.event.inputs.feature_branch != ''
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4
- name: Downloading Java
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Get Current Version
run: |
echo "POM_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
- name: Print Version
run: echo ${{env.POM_VERSION}}
- name: Split version code
uses: xom9ikk/split@v1
id: splitVersion
with:
string: ${{env.POM_VERSION}}
separator: "-"
limit: -1
- name: Set SNAPSHOT Version
run: echo "snapshotVersion=${{steps.splitVersion.outputs._0}}-SNAPSHOT" >> $GITHUB_ENV
- name: Commit & Push
run: |
git config user.name fda_shield_omoruyi
git config user.email [email protected]
git checkout $TRUNK_BRANCH
git pull -p
git checkout $FEATURE_BRANCH
mvn versions:set -DnewVersion=$snapshotVersion -DgenerateBackupPoms=false
git commit -am "Branch Ready For Review - Reverted back to original snapshot version $snapshotVersion"
git push origin $FEATURE_BRANCH
- name : Get Pull Requests
id: prList
run: |
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/pulls
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Print List
run: echo ${{steps.prList.outputs}}