|
| 1 | +name: A workflow for updating discovery artifacts |
| 2 | +# Controls when the action will run. |
| 3 | + |
| 4 | +on: |
| 5 | + # Triggers the workflow on pull request events but only for the master branch |
| 6 | + pull_request: |
| 7 | + branches: [ master ] |
| 8 | + |
| 9 | + # Allows you to run this workflow manually from the Actions tab |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + name: Update Discovery Artifacts PR |
| 15 | + runs-on: ubuntu-latest |
| 16 | + if: ${{github.event.pull_request.user.login == 'parthea' && github.event.pull_request.title == 'Add github action to update discovery artifacts'}} |
| 17 | + steps: |
| 18 | + - name: Check out working directory for changes |
| 19 | + uses: actions/checkout@v2 |
| 20 | + with: |
| 21 | + ref: refs/heads/master |
| 22 | + path: ./branch |
| 23 | + fetch-depth: '0' |
| 24 | + |
| 25 | + - name: Check out branch with scripts |
| 26 | + uses: actions/checkout@v2 |
| 27 | + with: |
| 28 | + ref: refs/heads/add-github-action-to-update-discovery-artifacts |
| 29 | + path: ./branch_with_scripts |
| 30 | + fetch-depth: '0' |
| 31 | + |
| 32 | + - name: Check out master |
| 33 | + uses: actions/checkout@v2 |
| 34 | + with: |
| 35 | + ref: refs/heads/master |
| 36 | + path: ./master |
| 37 | + |
| 38 | + - name: Create branch |
| 39 | + run: | |
| 40 | + git checkout -b update-discovery-artifacts |
| 41 | + working-directory: ./branch |
| 42 | + |
| 43 | + - name: Clone discovery artifacts from discovery-artifact manager |
| 44 | + uses: actions/checkout@v2 |
| 45 | + with: |
| 46 | + repository: googleapis/discovery-artifact-manager |
| 47 | + path: ./discovery-artifact-manager |
| 48 | + |
| 49 | + - name: Copy scripts |
| 50 | + run: | |
| 51 | + cp ../branch_with_scripts/changesummary.py changesummary.py |
| 52 | + cp ../branch_with_scripts/create_commits.sh create_commits.sh |
| 53 | + working-directory: ./branch |
| 54 | + |
| 55 | + - name: Copy discovery artifacts |
| 56 | + run: | |
| 57 | + cp ../discovery-artifact-manager/discoveries/*.json googleapiclient/discovery_cache/documents/ |
| 58 | + working-directory: ./branch |
| 59 | + |
| 60 | + - name: Get changed discovery artifacts |
| 61 | + run: git diff origin/master --name-only -- '*.json' | |
| 62 | + sed 's/.*\///' > changed_files |
| 63 | + working-directory: ./branch |
| 64 | + |
| 65 | + - name: Set up Python 3.9 |
| 66 | + uses: actions/setup-python@v1 |
| 67 | + with: |
| 68 | + python-version: 3.9 |
| 69 | + |
| 70 | + - name: Install pandas |
| 71 | + run: pip3 install pandas |
| 72 | + |
| 73 | + - name: Install google-api-python-client |
| 74 | + run: pip3 install -e . |
| 75 | + working-directory: ./branch |
| 76 | + |
| 77 | + - name: Patch to run the next step |
| 78 | + run: sed -i -e 's/if credentials is None/if False/g' googleapiclient/discovery.py |
| 79 | + working-directory: ./branch |
| 80 | + |
| 81 | + - name: Update the docs |
| 82 | + run: python3 describe.py |
| 83 | + working-directory: ./branch |
| 84 | + |
| 85 | + - name: Run Change Summary |
| 86 | + run: python3 changesummary.py |
| 87 | + working-directory: ./branch |
| 88 | + |
| 89 | + - name: Commit changes |
| 90 | + run: ./create_commits.sh |
| 91 | + working-directory: ./branch |
| 92 | + |
| 93 | + - name: Push changes |
| 94 | + run: git push -f --set-upstream origin update-discovery-artifacts |
| 95 | + working-directory: ./branch |
| 96 | + |
| 97 | + - name: Prepare summary for PR Body |
| 98 | + id: pr_body |
| 99 | + shell: bash |
| 100 | + run: | |
| 101 | + output=$(cat temp/allapis.summary) |
| 102 | + output="${output//'%'/'%25'}" |
| 103 | + output="${output//$'\n'/'%0A'}" |
| 104 | + output="${output//$'\r'/'%0D'}" |
| 105 | + echo "::set-output name=change_summary::$output" |
| 106 | + working-directory: ./branch |
| 107 | + |
| 108 | + - name: Create PR |
| 109 | + |
| 110 | + with: |
| 111 | + github-token: ${{secrets.YOSHI_CODE_BOT_TOKEN}} |
| 112 | + script: | |
| 113 | + const {owner, repo} = context.repo |
| 114 | + const branch = 'update-discovery-artifacts' |
| 115 | + let pr_body = `${{ steps.pr_body.outputs.change_summary }}` |
| 116 | + let pr_title = 'chore: Update discovery artifacts' |
| 117 | + const pull_requests = await github.pulls.list({ |
| 118 | + owner: owner, |
| 119 | + repo: repo, |
| 120 | + head: `${owner}:${branch}`, |
| 121 | + state: 'open' |
| 122 | + }); |
| 123 | +
|
| 124 | + if (pull_requests.data.length == 1) { |
| 125 | + prNumber = pull_requests.data[0].number |
| 126 | + await github.pulls.update({ |
| 127 | + owner: owner, |
| 128 | + repo: repo, |
| 129 | + pull_number: prNumber, |
| 130 | + title: pr_title, |
| 131 | + body: pr_body |
| 132 | + }); |
| 133 | + console.log('Updated PR') |
| 134 | + } |
| 135 | + else { |
| 136 | + const createPrResult = await github.pulls.create({ |
| 137 | + owner: owner, |
| 138 | + repo: repo, |
| 139 | + base: "master", |
| 140 | + head: `${owner}:${branch}`, |
| 141 | + title: pr_title, |
| 142 | + body: pr_body |
| 143 | + }); |
| 144 | + prNumber = createPrResult.data.number |
| 145 | + console.log('Created PR') |
| 146 | + } |
| 147 | +
|
| 148 | +# github.issues.addLabels({ |
| 149 | +# owner: owner, |
| 150 | +# repo: repo, |
| 151 | +# issue_number: prNumber, |
| 152 | +# labels: ['auto-merge'] |
| 153 | +# }); |
0 commit comments