Skip to content

Commit

Permalink
build: update Github Action to use fork from yoshi-code-bot (#2162)
Browse files Browse the repository at this point in the history
* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* trigger on cron job
  • Loading branch information
parthea committed Jan 8, 2024
1 parent 61d563a commit ce2912d
Showing 1 changed file with 16 additions and 42 deletions.
58 changes: 16 additions & 42 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@ jobs:
steps:
- name: Get current date
id: date
run: echo "::set-output name=current_date::$(date +'%Y-%m-%d')"
run: echo "::set-output name=current_date::$(date +'%Y-%m-%d-%HH%MM%SS')"

- name: Sync fork
run: gh repo sync $REPOSITORY -b $BRANCH_NAME
env:
REPOSITORY: 'yoshi-code-bot/google-api-python-client'
BRANCH_NAME: 'refs/heads/main'
GITHUB_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }}

- name: Check out main branch
uses: actions/checkout@v4
with:
ref: refs/heads/main
repository: 'yoshi-code-bot/google-api-python-client'
token: ${{secrets.YOSHI_CODE_BOT_TOKEN}}

- name: Create branch
run: |
Expand Down Expand Up @@ -68,7 +77,7 @@ jobs:
working-directory: ./scripts

- name: Push changes
run: git push -f --set-upstream origin update-discovery-artifacts-${{ steps.date.outputs.current_date }}
run: git push -u origin update-discovery-artifacts-${{ steps.date.outputs.current_date }}

- name: Prepare summary for PR Body
id: pr_body
Expand All @@ -83,43 +92,8 @@ jobs:
working-directory: ./scripts

- name: Create PR
uses: actions/github-script@v7.0.1
with:
github-token: ${{secrets.YOSHI_CODE_BOT_TOKEN}}
script: |
async function createPR () {
const { owner, repo } = context.repo
const branch = 'update-discovery-artifacts-${{ steps.date.outputs.current_date }}'
let prBody = `${{ steps.pr_body.outputs.change_summary }}`
const prTitle = 'chore: Update discovery artifacts'
const pullRequests = await github.rest.pulls.list({
owner: owner,
repo: repo,
head: `${owner}:${branch}`,
state: 'open'
})
if (pullRequests.data.length === 1) {
prNumber = pullRequests.data[0].number
await github.rest.pulls.update({
owner: owner,
repo: repo,
pull_number: prNumber,
title: prTitle,
body: prBody
})
console.log('Updated PR')
} else {
const createPrResult = await github.rest.pulls.create({
owner: owner,
repo: repo,
base: 'main',
head: `${owner}:${branch}`,
title: prTitle,
body: prBody
})
prNumber = createPrResult.data.number
console.log('Created PR')
}
}
createPR()
env:
GITHUB_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }}
PR_TITLE: "chore: Update discovery artifacts"
run: |
gh pr create -R "googleapis/google-api-python-client" -B "main" --title "$PR_TITLE" --body "${{ steps.pr_body.outputs.change_summary }}"

0 comments on commit ce2912d

Please sign in to comment.