2020 # * is a special character in YAML so you have to quote this string
2121 # Run this Github Action every Tuesday at 7 AM UTC
2222 - cron : ' 0 7 * * 2'
23+ workflow_dispatch :
2324
2425jobs :
2526 build :
@@ -29,19 +30,28 @@ jobs:
2930 steps :
3031 - name : Get current date
3132 id : date
32- run : echo "::set-output name=current_date::$(date +'%Y-%m-%d')"
33+ run : echo "::set-output name=current_date::$(date +'%Y-%m-%d-%HH%MM%SS')"
34+
35+ - name : Sync fork
36+ run : gh repo sync $REPOSITORY -b $BRANCH_NAME
37+ env :
38+ REPOSITORY : ' yoshi-code-bot/google-api-python-client'
39+ BRANCH_NAME : ' refs/heads/main'
40+ GITHUB_TOKEN : ${{ secrets.YOSHI_CODE_BOT_TOKEN }}
3341
3442 - name : Check out main branch
35- uses : actions/checkout@v3
43+ uses : actions/checkout@v4
3644 with :
3745 ref : refs/heads/main
46+ repository : ' yoshi-code-bot/google-api-python-client'
47+ token : ${{secrets.YOSHI_CODE_BOT_TOKEN}}
3848
3949 - name : Create branch
4050 run : |
4151 git checkout -b update-discovery-artifacts-${{ steps.date.outputs.current_date }}
4252
4353 - name : Set up Python 3.9
44- uses : actions/setup-python@v3
54+ uses : actions/setup-python@v5
4555 with :
4656 python-version : 3.9
4757
6878 working-directory : ./scripts
6979
7080 - name : Push changes
71- run : git push -f --set-upstream origin update-discovery-artifacts-${{ steps.date.outputs.current_date }}
81+ run : git push -u origin update-discovery-artifacts-${{ steps.date.outputs.current_date }}
7282
7383 - name : Prepare summary for PR Body
7484 id : pr_body
8393 working-directory : ./scripts
8494
8595 - name : Create PR
86- uses : actions/github-script@v6.1.0
87- with :
88- github-token : ${{secrets.YOSHI_CODE_BOT_TOKEN}}
89- script : |
90- async function createPR () {
91- const { owner, repo } = context.repo
92- const branch = 'update-discovery-artifacts-${{ steps.date.outputs.current_date }}'
93- let prBody = `${{ steps.pr_body.outputs.change_summary }}`
94- const prTitle = 'chore: Update discovery artifacts'
95- const pullRequests = await github.rest.pulls.list({
96- owner: owner,
97- repo: repo,
98- head: `${owner}:${branch}`,
99- state: 'open'
100- })
101-
102- if (pullRequests.data.length === 1) {
103- prNumber = pullRequests.data[0].number
104- await github.rest.pulls.update({
105- owner: owner,
106- repo: repo,
107- pull_number: prNumber,
108- title: prTitle,
109- body: prBody
110- })
111- console.log('Updated PR')
112- } else {
113- const createPrResult = await github.rest.pulls.create({
114- owner: owner,
115- repo: repo,
116- base: 'main',
117- head: `${owner}:${branch}`,
118- title: prTitle,
119- body: prBody
120- })
121- prNumber = createPrResult.data.number
122- console.log('Created PR')
123- }
124- }
125- createPR()
96+ env :
97+ GITHUB_TOKEN : ${{ secrets.YOSHI_CODE_BOT_TOKEN }}
98+ PR_TITLE : " chore: Update discovery artifacts"
99+ run : |
100+ gh pr create -R "googleapis/google-api-python-client" -B "main" --title "$PR_TITLE" --body "${{ steps.pr_body.outputs.change_summary }}"
0 commit comments