Skip to content

🚀 Release by develop hash #57

🚀 Release by develop hash

🚀 Release by develop hash #57

name: 🚀 Release by develop hash
on:
workflow_dispatch:
inputs:
commitHash:
description: 'Please supply a commit hash from the develop branch. You can find it in the commit history of develop branch, the first 6 characters are enough, e.g. c388cc. The release will encompass all contributions up to and including the specified head commit hash.'
required: true
type: string
dateSafeGuard:
description: 'Provide the current date in the format YYYY/MM/DD format.'
required: true
type: string
agreement:
description: 'By proceeding, the relevant commit hashes which encompass all commits below them in history will be merged into the main branch. Merging into the main branch should trigger a deployment to production. Please confirm you understand the above by typing: I understand and want to proceed!'
type: string
permissions:
contents: write
jobs:
merge-by-develop-hash:
runs-on: ubuntu-latest
env:
RELEASE_BRANCH: "main"
PREPARE_RELEASE_BRANCH: "prepare_release"
steps:
- name: Date safe-guard verification
run: |
currDate=$(date +%Y/%m/%d)
if [[ "$currDate" == "${{ inputs.dateSafeGuard }}" ]]; then
echo "✅ Date safe-guard is ok!"
else
echo "👹 Oops! The date provided ${currDate} doesn't correspond to ${{ inputs.date }}"
exit 1
fi
- name: Agreement verification
run: |
expectText="I understand and want to proceed!"
if [[ "${{ inputs.agreement }}" != "$expectText" ]]; then
echo "👹 Oops! To proceed you have to follow the agreement rule."
exit 1
fi
echo "✅ Agreement verified."
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: ${{ env.RELEASE_BRANCH }}
fetch-depth: 0
- name: Setup Git Config
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
- name: Verify commit hash in Develop
id: check_commit_hash
run: |
if ! git checkout develop; then
echo "👹 Oops! The develop branch wasn't found"
exit 1
fi
if ! git branch --contains "${{ github.event.inputs.commitHash }}" | grep -q develop > /dev/null; then
echo "👹 Oops! The commit hash wasn't found in the develop branch..."
exit 1
fi
- name: Create temporary release branch
run: |
if ! git checkout -b "${{ env.PREPARE_RELEASE_BRANCH }}" "${{ github.event.inputs.commitHash }}"; then
echo "👹 Oops! Failed to create the release preparation branch with name ${{ env.PREPARE_RELEASE_BRANCH }}. If the branch exists in the repository it's conflicting with the original intent for the goal of this step. You're advised to revise why the branch exists in the repository and do something about it, e.g. delete it or rename the target release branch name here."
exit 1
fi
echo "✅ Created the release preparation branch with name ${{ env.PREPARE_RELEASE_BRANCH }} successfuly"
- name: Merge into main
run: |
if ! git checkout "${{ env.RELEASE_BRANCH }}"; then
echo "👹 Oops! The develop branch wasn't found"
exit 1
fi
if ! git merge --ff-only ${{ github.event.inputs.commitHash }}; then
echo "👹 Oops! Failed to merge into main for some reason..."
exit 1
fi
if ! git push origin "${{ env.RELEASE_BRANCH }}"; then
echo "👹 Oops! Failed to push changes to the ${{ env.RELEASE_BRANCH }} branch for some reason..."
exit 1
fi
- name: Delete temporary release branch
run: |
if ! git branch -D "${{ env.PREPARE_RELEASE_BRANCH }}"; then
echo "👹 Oops! Failed to delete the release preparation branch with name ${{ env.PREPARE_RELEASE_BRANCH }} for some reason. You are advised to look into why this happens as you may have to delete this manually, as the original intent is to use it temporarily per job run."
exit 1
fi
echo "✅ Deleted the release preparation branch with name ${{ env.PREPARE_RELEASE_BRANCH }} successfuly"