forked from tofu-apis/revert-commit-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
86 lines (86 loc) · 4.34 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# action.yml
name: 'Revert Commit Action'
description: 'Automatically revert a given commit'
inputs:
commit-username:
description: 'Username to execute commits to Github with'
default: Automatic Revert Commit Bot
type: string
commit-email:
description: 'Email to execute commits to Github with'
default: [email protected]
type: string
github-token:
description: 'Github Action generated secret token for authentication purposes'
required: true
is-push-enabled:
description: 'Parameter to enable or disable the push of the revert (defaulting to false for safety/testing).'
required: true
default: 'false'
should-log-diff:
description: 'Boolean: true if git diff should be logged, false otherwise'
default: 'false'
outputs:
was-commit-reverted:
description: 'Boolean: true if commit was revert, false otherwise.'
value: ${{ steps.set-commit-hash-outputs.outputs.was-commit-reverted }}
reverted-commit-hash:
description: 'The commit hash of the commit that was reverted.'
value: ${{ steps.set-commit-hash-outputs.outputs.reverted-commit-hash }}
branding:
icon: 'rewind'
color: 'red'
runs:
using: "composite"
steps:
- uses: actions/[email protected]
with:
# Checkout with the latest for the given branch, so we can determine if there are any new commits.
ref: ${{ github.ref_name }}
# TODO | We may consider decreasing this for performance reasons in the future.
#
# Use 0 to ensure we get the full history for all branches/tags
# █ ██ █████ ██████ ███ ██ ██ ███ ██ ██████ ██ ██ ██
# ██ ██ ██ ██ ██ ██ ████ ██ ██ ████ ██ ██ ██ ██ ██
# ██ █ ██ ███████ ██████ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██
# ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
# ███ ███ ██ ██ ██ ██ ██ ████ ██ ██ ████ ██████ ██ ██ ██
# IMPORTANT: Without this, the git revert will delete ALL files!
# Make sure to add the fetch depth and set it to 0!
fetch-depth: 0
clean: false
- name: Create Local Revert Commit
run: |
echo "Locally reverting commit with hash: [${{ github.sha }}]"
git config --global user.email "${{ inputs.commit-email }}"
git config --global user.name "${{ inputs.commit-username }}"
git revert ${{ github.sha }} --no-edit
shell: bash
- name: Outputting diff of revert commit
if: ${{ inputs.should-log-diff == 'true' }}
# Comparing against branch minus one commit since the last commit should be the revert commit.
run: |
git config --global pager.diff false
git diff ${{ github.ref_name }}~1
shell: bash
- name: Automatic commit push to repo
if: ${{ inputs.is-push-enabled == 'true' }}
id: revert-commit-push
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Automatic Revert Commit for Commit Hash [${{ github.sha }}] [skip ci]
# Use amend with no edit but don't force since we know we generated a
# new auto revert commit that hasn't been submitted to the repo yet.
# This is effectively a no-op but is needed for git-auto-commit-action
# to force push the existing local commit that we have just created.
commit_options: '--amend --no-edit'
skip_dirty_check: false
commit_user_name: ${{ inputs.commit-username }}
commit_user_email: ${{ inputs.commit-email }}
- name: Set commit hash outputs
id: set-commit-hash-outputs
if: ${{ steps.revert-commit-push.outcome == 'success' }}
run: |
echo "was-commit-reverted=true" >> $GITHUB_OUTPUT
echo "reverted-commit-hash=${{ github.sha }}" >> $GITHUB_OUTPUT
shell: bash