|
| 1 | +name: System Agent Upgrade |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + system_agent_version: |
| 6 | + type: string |
| 7 | + description: "system agent version to update" |
| 8 | + source_author: |
| 9 | + type: string |
| 10 | + description: "Username of the source for this workflow run" |
| 11 | + |
| 12 | +env: |
| 13 | + SYSTEM_AGENT_VERSION: ${{ github.event.inputs.system_agent_version }} |
| 14 | + INPUT_SOURCE_AUTHOR: ${{ github.event.inputs.source_author }} |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + pull-requests: write |
| 19 | +jobs: |
| 20 | + system-agent-update: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Check out repository code |
| 24 | + uses: actions/checkout@v2 |
| 25 | + - name: Update system agent in files |
| 26 | + run: make system-agent-upgrade |
| 27 | + - name: Check for repository changes |
| 28 | + run: | |
| 29 | + if git diff --name-only --exit-code; then |
| 30 | + echo "No changes found in repository after 'go get'" |
| 31 | + echo "changes_exist=false" >> $GITHUB_ENV |
| 32 | + else |
| 33 | + echo "Changes found in repository after 'go get':" |
| 34 | + git diff --name-only |
| 35 | + echo "changes_exist=true" >> $GITHUB_ENV |
| 36 | + fi |
| 37 | + - name: Create branch, commit and push |
| 38 | + if: ${{ env.changes_exist == 'true' }} |
| 39 | + id: branch |
| 40 | + run: | |
| 41 | + BRANCH="githubaction-system-agent-upgrade-$(date +%Y-%m-%d-%H-%M-%S)" |
| 42 | + echo "::set-output name=branch::$BRANCH" |
| 43 | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 44 | + git config --global user.name "github-actions[bot]" |
| 45 | + git checkout -b "$BRANCH" |
| 46 | + git commit -a -m "updated system-agent to ${SYSTEM_AGENT_VERSION}" |
| 47 | + git push origin "$BRANCH" |
| 48 | + - name: Create Pull Request |
| 49 | + if: ${{ env.changes_exist == 'true' }} |
| 50 | + id: cpr |
| 51 | + |
| 52 | + env: |
| 53 | + SOURCE_BRANCH: ${{ steps.branch.outputs.branch }} |
| 54 | + with: |
| 55 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + script: | |
| 57 | + const { SYSTEM_AGENT_VERSION } = process.env |
| 58 | + let body = 'Auto-generated by GitHub Actions\n\n' |
| 59 | + if ( `${ process.env.INPUT_SOURCE_URL }` ) { |
| 60 | + body += `\nSource URL: ${ process.env.INPUT_SOURCE_URL }` |
| 61 | + } |
| 62 | + if ( `${ process.env.INPUT_SOURCE_AUTHOR }` ) { |
| 63 | + body += `\nSource AUTHOR: @${ process.env.INPUT_SOURCE_AUTHOR}` |
| 64 | + } |
| 65 | +
|
| 66 | + const { data: pr } = await github.rest.pulls.create({ |
| 67 | + title: `[${{ github.ref_name }}] update system-agent to ${SYSTEM_AGENT_VERSION}`, |
| 68 | + body: body, |
| 69 | + owner: context.repo.owner, |
| 70 | + repo: context.repo.repo, |
| 71 | + base: "${{ github.ref_name }}", |
| 72 | + head: `${ process.env.SOURCE_BRANCH }` |
| 73 | + }); |
| 74 | + await github.rest.issues.addLabels({ |
| 75 | + ...context.repo, |
| 76 | + issue_number: pr.number, |
| 77 | + labels: ["status/auto-created"], |
| 78 | + }); |
| 79 | + if ( `${ process.env.INPUT_SOURCE_AUTHOR }` ) { |
| 80 | + await github.rest.issues.addAssignees({ |
| 81 | + ...context.repo, |
| 82 | + issue_number: pr.number, |
| 83 | + assignees: [`${ process.env.INPUT_SOURCE_AUTHOR}`], |
| 84 | + }); |
| 85 | + } |
| 86 | + console.log('Created new pull request'); |
| 87 | + return pr.html_url; |
| 88 | + - name: Check outputs |
| 89 | + if: ${{ env.changes_exist == 'true' }} |
| 90 | + run: | |
| 91 | + echo "Pull Request URL - ${{ steps.cpr.outputs.result }}" |
0 commit comments