- Notifications
You must be signed in to change notification settings - Fork 27
chore: add renovate APIC-490 #522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits Select commit Hold shift + click to select a range
877f8cc chore: add renovate
millotp 6fe4c36 action
millotp faec510 fix tests
millotp f3d26be fix json
millotp 9ec95b8 fix pr title
millotp 0ce6e38 review
algolia-bot 476da34 bump issue
algolia-bot 41b2ff8 review
millotp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| name: Renovate | ||
| | ||
| on: | ||
| schedule: | ||
| - cron: '0 14 * * 5' | ||
| | ||
| jobs: | ||
| renovate: | ||
| name: Renovate | ||
| runs-on: ubuntu-20.04 | ||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| | ||
| - name: Setup | ||
| id: setup | ||
| uses: ./.github/actions/setup | ||
| with: | ||
| type: minimal | ||
| | ||
| - run: yarn workspace scripts renovateWeeklyPR | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.TOKEN_RELEASE_BOT }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "extends": [ | ||
| "config:js-app", | ||
| "algolia" | ||
| ], | ||
| "enabledManagers": [ | ||
| "npm", | ||
| "nvm" | ||
| ], | ||
| "baseBranches": [ | ||
| "chore/renovateBaseBranch" | ||
| ], | ||
| "packageRules": [ | ||
| { | ||
| "matchDepTypes": [ | ||
| "required_provider" | ||
| ], | ||
| "rangeStrategy": "bump" | ||
| } | ||
| ], | ||
| "prHourlyLimit": 10, | ||
| "prConcurrentLimit": 50 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| /* eslint-disable no-console */ | ||
| // script coming from crawler <3 | ||
| import type { Octokit } from '@octokit/rest'; | ||
| | ||
| import { getOctokit, OWNER, REPO, wait } from '../../common'; | ||
| | ||
| const BRANCH = 'chore/renovateBaseBranch'; | ||
| const BRANCH_BASE = 'main'; | ||
| const EMPTY_COMMIT_MSG = 'Automatic empty commit'; | ||
| | ||
| async function getRef( | ||
| octokit: Octokit, | ||
| branch: string | ||
| ): Promise<string | false> { | ||
| try { | ||
| const ref = await octokit.git.getRef({ | ||
| owner: OWNER, | ||
| repo: REPO, | ||
| ref: `heads/${branch}`, | ||
| }); | ||
| return ref.data.object.sha; | ||
| } catch (err) { | ||
| if (!(err instanceof Error) || (err as any).status !== 404) { | ||
| throw err; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| | ||
| async function createBranch(octokit: Octokit, sha: string): Promise<any> { | ||
| const create = await octokit.git.createRef({ | ||
| owner: OWNER, | ||
| repo: REPO, | ||
| ref: `refs/heads/${BRANCH}`, | ||
| sha, | ||
| }); | ||
| return create; | ||
| } | ||
| | ||
| async function deleteRef(octokit: Octokit): Promise<any> { | ||
| console.log(`Deleting ref for ${BRANCH}`); | ||
| const ref = await octokit.git.deleteRef({ | ||
| owner: OWNER, | ||
| repo: REPO, | ||
| ref: `heads/${BRANCH}`, | ||
| }); | ||
| return ref; | ||
| } | ||
| | ||
| async function updateRef(octokit: Octokit, sha: string): Promise<any> { | ||
| console.log(`Changing ref for ${BRANCH} to`, sha); | ||
| const ref = await octokit.git.updateRef({ | ||
| owner: OWNER, | ||
| repo: REPO, | ||
| ref: `heads/${BRANCH}`, | ||
| sha, | ||
| }); | ||
| return ref; | ||
| } | ||
| | ||
| async function getCommit(octokit: Octokit, sha: string): Promise<any> { | ||
| const commit = await octokit.git.getCommit({ | ||
| owner: OWNER, | ||
| repo: REPO, | ||
| commit_sha: sha, | ||
| }); | ||
| return commit.data; | ||
| } | ||
| | ||
| function isCommitAnEmptyCommit(commit: any): boolean { | ||
| return commit.message.search(EMPTY_COMMIT_MSG) >= 0; | ||
| } | ||
| | ||
| async function createEmptyCommit( | ||
| octokit: Octokit, | ||
| refCommit: any | ||
| ): Promise<any> { | ||
| console.log('Creating empty commit'); | ||
| const commit = await octokit.git.createCommit({ | ||
| owner: OWNER, | ||
| repo: REPO, | ||
| message: EMPTY_COMMIT_MSG, | ||
| tree: refCommit.tree.sha, | ||
| parents: [refCommit.sha], | ||
| }); | ||
| return commit.data; | ||
| } | ||
| | ||
| async function createPR(octokit: Octokit): Promise<any> { | ||
| // Next monday | ||
| const date = new Date(); | ||
| date.setDate(date.getDate() + 3); | ||
| | ||
| const title = `chore(scripts): dependencies ${ | ||
| date.toISOString().split('T')[0] | ||
| }`; | ||
| const { data } = await octokit.pulls.create({ | ||
| repo: REPO, | ||
| owner: OWNER, | ||
| title, | ||
| body: `Weekly dependencies update. | ||
| Contributes to #528 | ||
| `, | ||
| head: BRANCH, | ||
| base: BRANCH_BASE, | ||
| }); | ||
| return data; | ||
| } | ||
| | ||
| async function resetBranch( | ||
| octokit: Octokit, | ||
| refBase: string, | ||
| exists: boolean | ||
| ): Promise<void> { | ||
| if (exists) { | ||
| console.log('Deleting branch'); | ||
| await deleteRef(octokit); | ||
| await wait(5000); | ||
| } | ||
| | ||
| console.log('Creating branch'); | ||
| | ||
| await createBranch(octokit, refBase); | ||
| | ||
| const commit = await getCommit(octokit, refBase); | ||
| | ||
| const empty = await createEmptyCommit(octokit, commit); | ||
| await updateRef(octokit, empty.sha); | ||
| } | ||
| | ||
| (async (): Promise<void> => { | ||
| try { | ||
| const octokit = getOctokit(); | ||
| | ||
| const refBase = await getRef(octokit, BRANCH_BASE); | ||
| const refTarget = await getRef(octokit, BRANCH); | ||
| console.log(BRANCH_BASE, 'is at', refBase); | ||
| console.log(BRANCH, 'is at', refTarget); | ||
| | ||
| if (!refBase) { | ||
| console.error('no sha for base branch'); | ||
| return; | ||
| } | ||
| | ||
| if (refTarget) { | ||
| console.log('Branch exists'); | ||
| const commit = await getCommit(octokit, refTarget); | ||
| | ||
| if (isCommitAnEmptyCommit(commit)) { | ||
| console.log('Empty commit exists'); | ||
| return; | ||
| } | ||
| } | ||
| | ||
| await resetBranch(octokit, refBase, Boolean(refTarget)); | ||
| | ||
| console.log('Creating pull request'); | ||
| await createPR(octokit); | ||
| } catch (err) { | ||
| console.error(err); | ||
| } | ||
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
our CI will 🔥
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure it can handle it 😬