|
| 1 | +name: Generate Authors |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + secrets: |
| 6 | + token: |
| 7 | + required: true |
| 8 | + goassets-ref: |
| 9 | + default: master |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +jobs: |
| 14 | + check-secret: |
| 15 | + name: Check secret |
| 16 | + permissions: |
| 17 | + contents: none |
| 18 | + runs-on: ubuntu-latest |
| 19 | + if: startsWith(github.event.pull_request.head.ref, 'renovate/') == false |
| 20 | + outputs: |
| 21 | + is_token_set: ${{ steps.checksecret_job.outputs.is_token_set }} |
| 22 | + steps: |
| 23 | + - id: checksecret_job |
| 24 | + env: |
| 25 | + TOKEN: ${{ secrets.token }} |
| 26 | + run: | |
| 27 | + echo "is_token_set: ${{ env.TOKEN != '' }}" |
| 28 | + echo "::set-output name=is_token_set::${{ env.TOKEN != '' }}" |
| 29 | +
|
| 30 | + generate-authors: |
| 31 | + name: Generate Authors |
| 32 | + permissions: |
| 33 | + contents: write |
| 34 | + needs: [check-secret] |
| 35 | + if: needs.check-secret.outputs.is_token_set == 'true' |
| 36 | + runs-on: ubuntu-latest |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@v3 |
| 39 | + with: |
| 40 | + ref: ${{ github.head_ref }} |
| 41 | + fetch-depth: 0 |
| 42 | + token: ${{ secrets.token }} |
| 43 | + - name: Checkout .goassets |
| 44 | + uses: actions/checkout@v3 |
| 45 | + with: |
| 46 | + repository: pion/.goassets |
| 47 | + path: ${{ github.workspace }}/.github/.goassets |
| 48 | + ref: ${{ inputs.goassets-ref }} |
| 49 | + |
| 50 | + - name: Generate the authors file |
| 51 | + run: .github/.goassets/scripts/generate-authors.sh |
| 52 | + |
| 53 | + - name: Add the authors file to git |
| 54 | + run: git add AUTHORS.txt |
| 55 | + |
| 56 | + - name: Get last commit message |
| 57 | + id: last-commit-message |
| 58 | + run: | |
| 59 | + COMMIT_MSG=$(git log -1 --pretty=%B) |
| 60 | + COMMIT_MSG="${COMMIT_MSG//'%'/'%25'}" |
| 61 | + COMMIT_MSG="${COMMIT_MSG//$'\n'/'%0A'}" |
| 62 | + COMMIT_MSG="${COMMIT_MSG//$'\r'/'%0D'}" |
| 63 | + echo "::set-output name=msg::$COMMIT_MSG" |
| 64 | +
|
| 65 | + - name: Get last commit author |
| 66 | + id: last-commit-author |
| 67 | + run: echo "::set-output name=msg::$(git log -1 --pretty='%aN <%ae>')" |
| 68 | + |
| 69 | + - name: Check if AUTHORS.txt file has changed |
| 70 | + id: git-status-output |
| 71 | + run: echo "::set-output name=msg::$(git status -s | wc -l)" |
| 72 | + |
| 73 | + - name: Commit and push |
| 74 | + if: ${{ steps.git-status-output.outputs.msg != '0' }} |
| 75 | + run: | |
| 76 | + git config user.email $(echo "${{ steps.last-commit-author.outputs.msg }}" | sed 's/\(.\+\) <\(\S\+\)>/\2/') |
| 77 | + git config user.name $(echo "${{ steps.last-commit-author.outputs.msg }}" | sed 's/\(.\+\) <\(\S\+\)>/\1/') |
| 78 | + git add AUTHORS.txt |
| 79 | + git commit --amend --no-edit |
| 80 | + git push --force https://github.com/${GITHUB_REPOSITORY} $(git symbolic-ref -q --short HEAD) |
0 commit comments