|
| 1 | +name: 'Handle Specific Code of Conduct Scenarios' |
| 2 | +description: 'Handles scenarios for missing Code of Conduct or outdated Contributor Covenant version.' |
| 3 | +inputs: |
| 4 | + USER_GITHUB_TOKEN: |
| 5 | + description: 'User GitHub Token' |
| 6 | + required: true |
| 7 | + EVENT_ACTION: |
| 8 | + description: 'Event action that triggered the workflow' |
| 9 | + required: true |
| 10 | + |
| 11 | +runs: |
| 12 | + using: 'composite' |
| 13 | + steps: |
| 14 | + - name: Checkout repository |
| 15 | + uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + persist-credentials: false |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Configure Git user |
| 21 | + shell: bash |
| 22 | + run: | |
| 23 | + git config --global user.name 'BigBOSS-SOM' |
| 24 | + git config --global user.email 'bigboss.som@proton.me' |
| 25 | +
|
| 26 | + - name: Authenticate for git fetch |
| 27 | + shell: bash |
| 28 | + run: | |
| 29 | + git remote set-url origin https://BigBOSS-SOM:${{ inputs.USER_GITHUB_TOKEN }}@github.com/${{ github.repository }}.git |
| 30 | +
|
| 31 | + - name: Fetch all branches |
| 32 | + shell: bash |
| 33 | + run: git fetch --all |
| 34 | + |
| 35 | + - name: Create or switch to branch |
| 36 | + shell: bash |
| 37 | + run: | |
| 38 | + if [ "${{ inputs.EVENT_ACTION }}" == "no_code_of_conduct" ]; then |
| 39 | + branch="add-code-of-conduct" |
| 40 | + elif [ "${{ inputs.EVENT_ACTION }}" == "handle_contributor_covenant_1_4" ]; then |
| 41 | + branch="update-code-of-conduct" |
| 42 | + fi |
| 43 | + if git show-ref --verify --quiet refs/heads/$branch; then |
| 44 | + git checkout $branch |
| 45 | + else |
| 46 | + git checkout -b $branch |
| 47 | + fi |
| 48 | +
|
| 49 | + - name: Add or Update CODE_OF_CONDUCT.md |
| 50 | + shell: bash |
| 51 | + run: | |
| 52 | + cp $GITHUB_ACTION_PATH/.github/templates/CODE_OF_CONDUCT.md . |
| 53 | + git add CODE_OF_CONDUCT.md |
| 54 | + if [ "${{ inputs.EVENT_ACTION }}" == "no_code_of_conduct" ]; then |
| 55 | + git commit -m "Add CODE_OF_CONDUCT.md" || echo "No changes to commit" |
| 56 | + elif [ "${{ inputs.EVENT_ACTION }}" == "handle_contributor_covenant_1_4" ]; then |
| 57 | + git commit -m "Update CODE_OF_CONDUCT.md to Contributor Covenant 2.1" || echo "No changes to commit" |
| 58 | + fi |
| 59 | +
|
| 60 | + - name: Push changes |
| 61 | + shell: bash |
| 62 | + env: |
| 63 | + USER_GITHUB_TOKEN: ${{ inputs.USER_GITHUB_TOKEN }} |
| 64 | + run: | |
| 65 | + git remote set-url origin https://BigBOSS-SOM:${{ inputs.USER_GITHUB_TOKEN }}@github.com/${{ github.repository }}.git |
| 66 | + if [ "${{ inputs.EVENT_ACTION }}" == "no_code_of_conduct" ]; then |
| 67 | + git push -u origin add-code-of-conduct |
| 68 | + elif [ "${{ inputs.EVENT_ACTION }}" == "handle_contributor_covenant_1_4" ]; then |
| 69 | + git push -u origin update-code-of-conduct |
| 70 | + fi |
| 71 | +
|
| 72 | + - name: Set Pull Request Branch |
| 73 | + shell: bash |
| 74 | + run: | |
| 75 | + if [ "${{ inputs.EVENT_ACTION }}" == "no_code_of_conduct" ]; then |
| 76 | + echo "PULL_REQUEST_FROM_BRANCH=add-code-of-conduct" >> $GITHUB_ENV |
| 77 | + elif [ "${{ inputs.EVENT_ACTION }}" == "handle_contributor_covenant_1_4" ]; then |
| 78 | + echo "PULL_REQUEST_FROM_BRANCH=update-code-of-conduct" >> $GITHUB_ENV |
| 79 | + fi |
| 80 | +
|
1 | 81 | - name: Set Pull Request Environment Variables
|
2 | 82 | shell: bash
|
3 | 83 | run: |
|
|
0 commit comments