-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
102 lines (92 loc) · 4.2 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: 'Handle Specific Code of Conduct Scenarios'
description: 'Handles scenarios for missing Code of Conduct or outdated Contributor Covenant version.'
inputs:
USER_GITHUB_TOKEN:
description: 'User GitHub Token'
required: true
EVENT_ACTION:
description: 'Event action that triggered the workflow'
required: true
runs:
using: 'composite'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
- name: Configure Git user
shell: bash
run: |
git config --global user.name 'BigBOSS-SOM'
git config --global user.email '[email protected]'
- name: Authenticate for git fetch
shell: bash
run: |
git remote set-url origin https://BigBOSS-SOM:${{ inputs.USER_GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
- name: Fetch all branches
shell: bash
run: git fetch --all
- name: Create or switch to branch
shell: bash
run: |
if [ "${{ inputs.EVENT_ACTION }}" == "no_code_of_conduct" ]; then
branch="add-code-of-conduct"
elif [ "${{ inputs.EVENT_ACTION }}" == "handle_contributor_covenant_1_4" ]; then
branch="update-code-of-conduct"
fi
if git show-ref --verify --quiet refs/heads/$branch; then
git checkout $branch
else
git checkout -b $branch
fi
- name: Add or Update CODE_OF_CONDUCT.md
shell: bash
run: |
cp $GITHUB_ACTION_PATH/.github/templates/CODE_OF_CONDUCT.md .
git add CODE_OF_CONDUCT.md
if [ "${{ inputs.EVENT_ACTION }}" == "no_code_of_conduct" ]; then
git commit -m "Add CODE_OF_CONDUCT.md" || echo "No changes to commit"
elif [ "${{ inputs.EVENT_ACTION }}" == "handle_contributor_covenant_1_4" ]; then
git commit -m "Update CODE_OF_CONDUCT.md to Contributor Covenant 2.1" || echo "No changes to commit"
fi
- name: Push changes
shell: bash
env:
USER_GITHUB_TOKEN: ${{ inputs.USER_GITHUB_TOKEN }}
run: |
git remote set-url origin https://BigBOSS-SOM:${{ inputs.USER_GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
if [ "${{ inputs.EVENT_ACTION }}" == "no_code_of_conduct" ]; then
git push -u origin add-code-of-conduct
elif [ "${{ inputs.EVENT_ACTION }}" == "handle_contributor_covenant_1_4" ]; then
git push -u origin update-code-of-conduct
fi
- name: Set Pull Request Branch
shell: bash
run: |
if [ "${{ inputs.EVENT_ACTION }}" == "no_code_of_conduct" ]; then
echo "PULL_REQUEST_FROM_BRANCH=add-code-of-conduct" >> $GITHUB_ENV
elif [ "${{ inputs.EVENT_ACTION }}" == "handle_contributor_covenant_1_4" ]; then
echo "PULL_REQUEST_FROM_BRANCH=update-code-of-conduct" >> $GITHUB_ENV
fi
- name: Set Pull Request Environment Variables
shell: bash
run: |
if [ "${{ inputs.EVENT_ACTION }}" == "no_code_of_conduct" ]; then
echo "PULL_REQUEST_FROM_BRANCH=add-code-of-conduct" >> $GITHUB_ENV
echo "PULL_REQUEST_TITLE=Add Code of Conduct" >> $GITHUB_ENV
echo "PULL_REQUEST_BODY=This pull request adds a Code of Conduct to the repository." >> $GITHUB_ENV
elif [ "${{ inputs.EVENT_ACTION }}" == "handle_contributor_covenant_1_4" ]; then
echo "PULL_REQUEST_FROM_BRANCH=update-code-of-conduct" >> $GITHUB_ENV
echo "PULL_REQUEST_TITLE=Update Code of Conduct to Contributor Covenant 2.1" >> $GITHUB_ENV
echo "PULL_REQUEST_BODY=We have detected that your current Code of Conduct is based on Contributor Covenant version 1.4. It would be great to update it to the latest version 2.1 to ensure it includes the most recent improvements and guidelines." >> $GITHUB_ENV
fi
- name: Create Pull Request
uses: vsoch/pull-request-action@master
env:
GITHUB_TOKEN: ${{ inputs.USER_GITHUB_TOKEN }}
PULL_REQUEST_BRANCH: "main"
PULL_REQUEST_FROM_BRANCH: ${{ env.PULL_REQUEST_FROM_BRANCH }}
PULL_REQUEST_TITLE: ${{ env.PULL_REQUEST_TITLE }}
PULL_REQUEST_BODY: ${{ env.PULL_REQUEST_BODY }}
PULL_REQUEST_LABELS: "code of conduct, documentation"