-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace octokit use with internal JSON file
Python tags changes are slow so a static file makes sense. A new workflow is created to keep the file updated
- Loading branch information
1 parent
a179f31
commit 24180c4
Showing
7 changed files
with
103 additions
and
71 deletions.
There are no files selected for viewing
This file contains 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,50 @@ | ||
const core = require('@actions/core'); | ||
const github = require('@actions/github'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
async function updateJson() { | ||
const octokit = github.getOctokit(process.env['GITHUB_TOKEN']); | ||
const tags = []; | ||
let index = 1; | ||
let changed = true; | ||
while (changed) { | ||
changed = false; | ||
let response = null; | ||
core.startGroup(`Getting tags ${(index - 1) * 100}-${index * 100}`); | ||
while (response === null) { | ||
try { | ||
response = await octokit.rest.repos.listTags({ | ||
owner: 'python', | ||
page: index, | ||
per_page: 100, | ||
repo: 'cpython' | ||
}); | ||
} catch (error) { | ||
core.info('Rest API rate limit reached. Retrying in 60 seconds...'); | ||
await sleep(60); | ||
} | ||
} | ||
if (response.status !== 200) { | ||
throw new Error('Error in getting tags.'); | ||
} | ||
for (const tag of response.data) { | ||
changed = true; | ||
core.info(`Received tag ${tag.name}`) | ||
tags.push({version: tag.name, zipBall: tag.zipball_url}); | ||
} | ||
core.endGroup(); | ||
index++; | ||
} | ||
return JSON.stringify(tags, null, 2); | ||
} | ||
|
||
const jsonPath = path.join(path.dirname(path.dirname(__dirname)), 'src', 'builder', 'tags.json'); | ||
core.info(`Updating ${jsonPath}`); | ||
|
||
updateJson().then((jsonString) => { | ||
core.startGroup('Final JSON string'); | ||
core.info(jsonString); | ||
core.endGroup(); | ||
fs.writeFileSync(jsonPath, jsonString) | ||
}) |
This file contains 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,38 @@ | ||
name: Update JSON Data | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: 0 0 * * * | ||
|
||
jobs: | ||
update_cpython_tags: | ||
runs-on: ubuntu-latest | ||
name: Update CPython JSON tags | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: master | ||
- name: Setup NodeJS 16 | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16 | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Update JSON data | ||
run: node ./.github/scripts/generate_tags.js | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Create or update pull request | ||
uses: peter-evans/create-pull-request@v4 | ||
with: | ||
commit-message: Update CPython JSON tags data | ||
branch: create-pull-request/cpython-json-tags | ||
delete-branch: true | ||
title: Update CPython JSON tags data | ||
body: | | ||
Automated JSON data update by [update_json.yml](https://github.com/MatteoH2O1999/build-and-install-python/tree/master/.github/workflows/update_json.yml) | ||
assignees: ${{ github.repository_owner }} | ||
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com> | ||
token: ${{ secrets.PAT_TOKEN }} |
This file contains 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 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,6 @@ | ||
[ | ||
{ | ||
"version": "placeholder", | ||
"zipBall": "url" | ||
} | ||
] |
This file contains 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 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 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