Check for updates #74
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
name: "Check for updates" | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: >- | |
15 15 * * * | |
jobs: | |
check: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: read | |
steps: | |
- name: Check for updates | |
id: check | |
uses: silverlyra/[email protected] | |
with: | |
script: | | |
const npmResponse = await fetch('https://registry.npmjs.org/kubernetes-types/'); | |
const npmTags = (await npmResponse.json())['dist-tags']; | |
const [major, minor] = npmTags.latest.split('.', 2).map(Number); | |
const next = `${major}.${minor + 1}`; | |
console.log(`Latest package: ${npmTags.latest}; checking for Kubernetes ${next}`); | |
const { data: refs } = await github.rest.git.listMatchingRefs({ | |
owner: 'kubernetes', | |
repo: 'kubernetes', | |
ref: `tags/v${next}.0`, | |
}); | |
// exclude pre-releases | |
const ref = refs.find(({ ref }) => ref === `refs/tags/v${next}.0`); | |
const found = ref != null; | |
if (found) { | |
console.log(`Found new release: ${next}.0`); | |
const { data: {download_url: url} } = await github.rest.repos.getContent({ | |
owner: 'kubernetes', | |
repo: 'kubernetes', | |
ref: `v${next}.0`, | |
path: 'api/openapi-spec/swagger.json', | |
}); | |
const response = await fetch(url); | |
const spec = await response.text(); | |
await fs.writeFile(path.join(env.RUNNER_TEMP, 'swagger.json'), spec, 'utf-8'); | |
console.log(`Saved swagger.json to ${env.RUNNER_TEMP}`); | |
} | |
return { next, found, ref }; | |
- name: Checkout repository | |
if: fromJson(steps.check.outputs.result).found | |
uses: actions/checkout@v4 | |
- name: Setup node.js | |
if: fromJson(steps.check.outputs.result).found | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20.x' | |
registry-url: 'https://registry.npmjs.org' | |
cache: npm | |
- name: Update types | |
if: fromJson(steps.check.outputs.result).found | |
id: update | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | |
VERSION: v${{ fromJson(steps.check.outputs.result).next }} | |
run: | | |
npm ci | |
npm run build | |
echo "Generating type package for ${VERSION}" | |
mkdir -p types | |
./bin/generate-kubernetes-types --api "$VERSION" --file "${RUNNER_TEMP}/swagger.json" | |
cd "./types/${VERSION}.0" | |
npm publish |