2828 description : ' Issue link in format https://github.com/wazuh/<REPO>/issues/<ISSUE-NUMBER>'
2929 required : true
3030 type : string
31+ revert :
32+ description : ' Set to true to revert the bump changes applied for this issue'
33+ default : false
34+ required : false
35+ type : boolean
3136 id :
3237 description : ' Optional identifier for the run'
3338 required : false
@@ -107,7 +112,13 @@ jobs:
107112 fi
108113
109114 issue_number=$(echo "${{ inputs.issue-link }}" | awk -F'/' '{print $NF}')
110- BRANCH_NAME="enhancement/wqa${issue_number}-bump-${{ github.ref_name }}"
115+ if [[ "${{ inputs.revert }}" == "true" ]]; then
116+ BRANCH_NAME="enhancement/wqa${issue_number}-revert-bump-${{ github.ref_name }}"
117+ echo "pr_title=Revert bump ${{ github.ref_name }} branch" >> $GITHUB_OUTPUT
118+ else
119+ BRANCH_NAME="enhancement/wqa${issue_number}-bump-${{ github.ref_name }}"
120+ echo "pr_title=Bump ${{ github.ref_name }} branch" >> $GITHUB_OUTPUT
121+ fi
111122 echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
112123 echo "script_params=${script_params}" >> $GITHUB_OUTPUT
113124
@@ -116,22 +127,68 @@ jobs:
116127 git checkout -b ${{ steps.vars.outputs.branch_name }}
117128
118129 - name : Make version bump changes
130+ if : inputs.revert != true
119131 run : |
120132 echo "Running bump script"
121133 bash ${{ env.BUMP_SCRIPT_PATH }} ${{ steps.vars.outputs.script_params }}
122134
123- - name : Commit and push changes
135+ - name : Commit changes (Bump)
136+ if : inputs.revert != true
124137 run : |
125138 git add .
126139 git commit -m "feat: bump ${{ github.ref_name }}"
140+
141+ - name : Fetch full history (Revert)
142+ if : inputs.revert == true
143+ run : git fetch --unshallow
144+
145+ - name : Revert references (Revert)
146+ id : revert_step
147+ if : inputs.revert == true
148+ run : |
149+ ISSUE_NUMBER=$(echo "${{ inputs.issue-link }}" | awk -F'/' '{print $NF}')
150+
151+ BUMP_BRANCH="enhancement/wqa${ISSUE_NUMBER}-bump-${{ github.ref_name }}"
152+
153+ PR_NUMBER=$(gh pr list --head "$BUMP_BRANCH" --base "${{ github.ref_name }}" --state merged --json number --jq '.[0].number')
154+
155+ if [ -z "$PR_NUMBER" ] || [ "$PR_NUMBER" == "null" ]; then
156+ echo "Error: The original PR for the bump was not found"
157+ echo "Searching merged PR from: $BUMP_BRANCH to ${{ github.ref_name }}"
158+ exit 1
159+ fi
160+
161+ echo "Original PR found: #$PR_NUMBER"
162+
163+ MERGE_COMMIT=$(gh pr view $PR_NUMBER --json mergeCommit --jq '.mergeCommit.oid')
164+
165+ git revert -m 1 $MERGE_COMMIT --no-commit
166+
167+ # Remove the files to prevent them from being included in the revert commit
168+ git checkout HEAD -- VERSION.json 2>/dev/null || true
169+ git checkout HEAD -- CHANGELOG.md 2>/dev/null || true
170+ # Add any other repository-specific version files here
171+
172+ if git diff --staged --quiet; then
173+ echo "No references to revert. Skipping commit."
174+ echo "has_changes=false" >> $GITHUB_OUTPUT
175+ else
176+ git commit -m "feat: revert ${{ github.ref_name }} references"
177+ echo "has_changes=true" >> $GITHUB_OUTPUT
178+ fi
179+
180+ - name : Push changes
181+ if : inputs.revert != true || (inputs.revert == true && steps.revert_step.outputs.has_changes == 'true')
182+ run : |
127183 git push origin ${{ steps.vars.outputs.branch_name }}
128184
129185 - name : Create pull request
186+ if : inputs.revert != true || (inputs.revert == true && steps.revert_step.outputs.has_changes == 'true')
130187 id : create_pr
131188 run : |
132189 gh auth setup-git
133190 PR_URL=$(gh pr create \
134- --title "Bump ${{ github.ref_name }} branch " \
191+ --title "${{ steps.vars.outputs.pr_title }}" \
135192 --body "Issue: ${{ inputs.issue-link }}" \
136193 --base ${{ github.ref_name }} \
137194 --head ${{ steps.vars.outputs.branch_name }})
@@ -140,14 +197,25 @@ jobs:
140197 echo "pull_request_url=${PR_URL}" >> $GITHUB_OUTPUT
141198
142199 - name : Merge pull request
200+ if : inputs.revert != true || (inputs.revert == true && steps.revert_step.outputs.has_changes == 'true')
143201 run : |
144- # Any checks for the PR are bypassed since the branch is expected to be functional (i.e. the bump process does not introduce any bugs)
202+ # Any checks for the PR are bypassed since the branch is expected to be functional
145203 gh pr merge "${{ steps.create_pr.outputs.pull_request_url }}" --merge --admin
146204
147- - name : Show logs
205+ - name : Show bump logs
206+ if : inputs.revert != true
148207 run : |
149208 echo "Bump complete."
150209 echo "Branch: ${{ steps.vars.outputs.branch_name }}"
151210 echo "PR: ${{ steps.create_pr.outputs.pull_request_url }}"
152211 echo "Bumper scripts logs:"
153212 cat ${BUMP_LOG_PATH}/repository_bumper*log
213+
214+ - name : Show revert logs
215+ if : inputs.revert == true
216+ run : |
217+ echo "Revert bump complete."
218+ echo "Branch: ${{ steps.vars.outputs.branch_name }}"
219+ echo "PR: ${{ steps.create_pr.outputs.pull_request_url }}"
220+ echo "Revert bumper scripts logs:"
221+ cat ${BUMP_LOG_PATH}/repository_bumper*log || true
0 commit comments