chore: cleanup and improve CI (#319)

Co-authored-by: Jeroen Claassens <jeroen.claassens@live.nl>
This commit is contained in:
Vlad Frangu
2022-02-14 01:53:49 +02:00
committed by GitHub
parent ed1f717679
commit 9af4b4776b
27 changed files with 3593 additions and 1451 deletions

View File

@@ -1,3 +0,0 @@
{
"plugins": ["@babel/plugin-syntax-top-level-await"]
}

8
.eslintrc.json Normal file
View File

@@ -0,0 +1,8 @@
{
"extends": "marine/prettier/node",
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.eslint.json",
"extraFileExtensions": [".mjs"]
}
}

View File

@@ -1,3 +1,3 @@
**Please describe the changes this PR makes and why it should be merged:**
**Reference Discord API Docs PRs or commits:**
**If applicable, please reference Discord API Docs PRs or commits that influenced this PR:**

2
.github/SUPPORT.md vendored
View File

@@ -5,4 +5,4 @@ We only use this issue tracker for bug reports and feature request. We are not a
For general questions about discord-api-types installation and use please ask in [GitHub Discussions](https://github.com/discordjs/discord-api-types/discussions),
or in the dedicated support channels in our Discord server: https://discord.gg/djs
Any issues that don't directly involve a bug or a feature request will likely be closed and redirected.
Any issues that don't directly involve a bug or a feature request will likely be redirected or closed.

53
.github/labels.yml vendored Normal file
View File

@@ -0,0 +1,53 @@
# General labels
- name: 'semver:major'
color: 'c10f47'
- name: 'semver:minor'
color: 'e4f486'
- name: 'semver:patch'
color: 'e8be8b'
- name: 'question (please use Discord instead)'
color: 'd876e3'
- name: 'regression'
color: 'ea8785'
- name: 'wontfix'
color: 'ffffff'
- name: 'chore'
color: 'ffffff'
- name: 'ci'
color: '0075ca'
- name: 'dependencies'
color: '276bd1'
- name: 'duplicate'
color: 'cfd3d7'
- name: 'feature request'
color: 'fcf95a'
- name: 'bug'
color: 'd73a4a'
- name: 'backlog'
color: '7ef7ef'
- name: 'good first issue'
color: '7057ff'
- name: 'has PR'
color: '4b1f8e'
- name: 'help wanted'
color: '008672'
# Topic labels
- name: 'topic:deno'
color: 'aed5fc'
- name: 'topic:gateway'
color: 'aed5fc'
- name: 'topic:payloads'
color: 'aed5fc'
- name: 'topic:rest'
color: 'aed5fc'
- name: 'topic:rpc'
color: 'aed5fc'
- name: 'topic:scripts'
color: 'aed5fc'
- name: 'topic:tests'
color: 'aed5fc'
- name: 'topic:utils'
color: 'aed5fc'
- name: 'topic:voice'
color: 'aed5fc'

28
.github/workflows/check-deno.yml vendored Normal file
View File

@@ -0,0 +1,28 @@
name: Deno
on:
pull_request:
types:
- opened
- synchronize
jobs:
check_deno:
name: Ensure Deno types are in sync with the code
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@v2
- name: Use Node.js v16
uses: actions/setup-node@v2
with:
node-version: 16
- name: Install Dependencies
run: npm ci
- name: Run Check Script
run: node ./scripts/actions/report-deno-not-ran.mjs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -28,40 +28,6 @@ jobs:
- name: Run TSC
run: npm run build:ci
deno:
name: Generate Deno compatible code
runs-on: ubuntu-latest
needs: testing
# Run workflow only if testing passes
if: needs.testing.result == 'success'
steps:
- name: Checkout Project
uses: actions/checkout@v2
- name: Use Node.js v16
uses: actions/setup-node@v2
with:
node-version: 16
- name: Install Dependencies
run: npm ci
- name: Build Files
run: npm run build:deno
- name: Set Git User and Email
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Commit and Push New Code
run: |
git add --all .
git commit -m "build: deno build for ${GITHUB_SHA}" || true
git push || true
tsd:
name: TSD checks
runs-on: ubuntu-latest

View File

@@ -0,0 +1,93 @@
name: Create PR for new releases and publish new version
on:
workflow_dispatch:
push:
branches:
- main
schedule:
# Run every Tuesday and Thursday at 12:00
- cron: '0 12 * * 2,4'
jobs:
create_pr:
name: Create PR for new version
runs-on: ubuntu-latest
if: github.repository_owner == 'discordjs' && github.event_name != 'push'
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install Node v16
uses: actions/setup-node@v2
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Set Git User and Email
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Bump version
run: node ./scripts/bump-version.mjs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create branch for changes, add all changes and push
run: |
git checkout -b "chore/release/$(jq --raw-output '.version' package.json)"
# Run changelog generation and deno scripts
npm run ci:pr
# Add all changes, commit and push
git add --all .
git commit -m "chore(release): $(jq --raw-output '.version' package.json) 🎉" -m "Build ran for ${GITHUB_SHA}"
git push -u origin "chore/release/$(jq --raw-output '.version' package.json)"
- name: Create Pull Request
run: node ./scripts/actions/create-pr.mjs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
create_release:
name: Create release and publish
runs-on: ubuntu-latest
if: github.repository_owner == 'discordjs' && github.event_name == 'push' && startsWith(github.event.head_commit.message, 'chore(release)') && !contains(github.event.head_commit.message, '[skip ci]')
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install Node v16
uses: actions/setup-node@v2
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Deprecate old versions
run: npx npm-deprecate --name "*" --package discord-api-types --message "No longer supported. Install the latest release!" || true
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
- name: Publish release to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
- name: Create GitHub release
run: node ./scripts/actions/create-release.mjs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

22
.github/workflows/labelsync.yml vendored Normal file
View File

@@ -0,0 +1,22 @@
name: Label Sync
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
push:
branches:
- main
paths:
- '.github/labels.yml'
jobs:
labelsync:
name: Label sync
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Label sync
uses: crazy-max/ghaction-github-labeler@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -2,14 +2,21 @@ name: Publish next
on:
workflow_dispatch:
schedule:
- cron: '0 */12 * * *'
push:
branches:
- main
jobs:
publish:
name: Publish to npm
name: Publish @next release to npm
runs-on: ubuntu-latest
if: github.repository_owner == 'discordjs' && !(github.event_name == 'push' && startsWith(github.event.head_commit.message, 'chore(release)'))
steps:
- name: Cancel previous publish attempts
uses: styfle/cancel-workflow-action@0.9.1
with:
access_token: ${{ github.token }}
- name: Checkout repository
uses: actions/checkout@v2
with:
@@ -25,18 +32,16 @@ jobs:
run: npm ci --ignore-scripts
- name: Bump version
run: npx standard-version
run: node ./scripts/bump-version.mjs
- name: Deprecate old @next versions
run: npx npm-deprecate --name "*next*" --package discord-api-types --message "No longer supported. Install the latest @next release" || true
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
- name: Deprecate old versions
run: npm deprecate discord-api-types@"~$(jq --raw-output '.version' package.json)-next" "No longer supported. Install the latest @next release" || true
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
- name: Publish new version
- name: Publish new @next version
run: |
npm version --git-tag-version=false $(jq --raw-output '.version' package.json)-next.$(git rev-parse --short HEAD).$(date +%s)
npm version $(jq --raw-output '.version' package.json)-next.$(git rev-parse --short HEAD).$(date +%s)
npm publish --tag next || true
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

8
.gitignore vendored
View File

@@ -6,10 +6,10 @@ globals.*map
globals.d.ts
globals.mjs
v*.js
v*.*map
v*.d.ts
v*.mjs
./v*.js
./v*.*map
./v*.d.ts
./v*.mjs
gateway/**/*.js
gateway/**/*.map

1
.npmrc
View File

@@ -2,4 +2,5 @@ audit=false
fund=false
legacy-peer-deps=true
tag-version-prefix=""
git-tag-version=false
message="chore(release): %s 🎉"

1
.prettierignore Normal file
View File

@@ -0,0 +1 @@
deno/

View File

@@ -694,7 +694,6 @@ export interface GatewayIdentify {
properties: GatewayIdentifyProperties;
compress?: boolean;
large_threshold?: number;
// eslint-disable-next-line prettier/prettier
shard?: [shard_id: number, shard_count: number];
presence?: RawGatewayPresenceUpdate;
guild_subscriptions?: boolean;

View File

@@ -122,7 +122,6 @@ export type GatewayActivityEmoji = Partial<Pick<APIEmoji, 'name' | 'animated'>>
*/
export interface GatewayActivityParty {
id?: string;
// eslint-disable-next-line prettier/prettier
size?: [currentSize: number, maxSize: number];
}

View File

@@ -694,7 +694,6 @@ export interface GatewayIdentify {
properties: GatewayIdentifyProperties;
compress?: boolean;
large_threshold?: number;
// eslint-disable-next-line prettier/prettier
shard?: [shard_id: number, shard_count: number];
presence?: RawGatewayPresenceUpdate;
guild_subscriptions?: boolean;

4387
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -73,6 +73,8 @@
"build:ci": "tsc --noEmit --incremental false",
"build:deno": "node ./scripts/deno.mjs",
"build:node": "tsc && run-p esm:*",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"ci:pr": "run-s changelog lint build:deno",
"clean:deno": "rimraf deno/",
"clean:node": "rimraf {gateway,payloads,rest,rpc,voice,utils}/**/*.{js,mjs,d.ts,*map} {globals,v*}.{js,mjs,d.ts,*map}",
"clean": "run-p clean:*",
@@ -84,15 +86,14 @@
"esm:utils": "gen-esm-wrapper ./utils/index.js ./utils/index.mjs",
"esm:versions": "node ./scripts/versions.mjs",
"esm:voice": "gen-esm-wrapper ./voice/index.js ./voice/index.mjs",
"lint": "eslint --fix --ext mjs,ts {gateway,payloads,rest,rpc,voice,utils}/**/*.ts {globals,v*}.ts",
"lint": "prettier --write . && eslint --fix --ext mjs,ts {gateway,payloads,rest,rpc,voice,utils}/**/*.ts {globals,v*}.ts scripts/**/*.{mjs,ts}",
"postpublish": "run-s clean:node build:deno",
"prepare": "is-ci || husky install",
"prepublishOnly": "run-s clean test:lint build:node",
"test:lint": "eslint --ext mjs,ts {gateway,payloads,rest,rpc,voice,utils}/**/*.ts {globals,v*}.ts",
"test:lint": "prettier --check . && eslint --ext mjs,ts {gateway,payloads,rest,rpc,voice,utils}/**/*.ts {globals,v*}.ts scripts/**/*.{mjs,ts}",
"pretest:types": "tsc",
"test:types": "tsd",
"posttest:types": "npm run clean:node",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
"posttest:types": "npm run clean:node"
},
"keywords": [
"discord",
@@ -106,62 +107,36 @@
"{gateway,payloads,rest,rpc,voice,utils}/**/*.{js,js.map,d.ts,d.ts.map,mjs}",
"{globals,v*}.{js,js.map,d.ts,d.ts.map,mjs}"
],
"engines": {
"node": ">=12"
},
"devDependencies": {
"@babel/core": "^7.16.5",
"@babel/eslint-parser": "^7.16.5",
"@babel/plugin-syntax-top-level-await": "^7.14.5",
"@commitlint/cli": "^15.0.0",
"@commitlint/config-angular": "^15.0.0",
"@types/node": "^17.0.4",
"@typescript-eslint/eslint-plugin": "^5.8.0",
"@typescript-eslint/parser": "^5.8.0",
"conventional-changelog-cli": "^2.1.1",
"eslint": "^8.5.0",
"eslint-config-marine": "^9.1.0",
"@commitlint/cli": "^16.1.0",
"@commitlint/config-angular": "^16.0.0",
"@favware/npm-deprecate": "^1.0.4",
"@octokit/action": "^3.18.0",
"@octokit/webhooks-types": "^5.4.0",
"@types/conventional-recommended-bump": "^6.1.0",
"@types/node": "^17.0.17",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"conventional-changelog-cli": "^2.2.2",
"conventional-recommended-bump": "^6.1.0",
"eslint": "^8.8.0",
"eslint-config-marine": "^9.3.2",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"gen-esm-wrapper": "^1.1.3",
"husky": "^7.0.4",
"is-ci": "^3.0.1",
"lint-staged": "^12.1.4",
"lint-staged": "^12.3.3",
"npm-run-all": "^4.1.5",
"prettier": "^2.5.1",
"pretty-quick": "^3.1.3",
"rimraf": "^3.0.2",
"tsd": "^0.19.0",
"typescript": "^4.5.4"
"tsd": "^0.19.1",
"typescript": "^4.5.5"
},
"repository": {
"type": "git",
"url": "https://github.com/discordjs/discord-api-types"
},
"eslintConfig": {
"extends": "marine/prettier/node",
"parserOptions": {
"project": "./tsconfig.eslint.json",
"extraFileExtensions": [
".mjs"
]
},
"rules": {
"@typescript-eslint/naming-convention": 0
},
"overrides": [
{
"files": [
"scripts/**/*.mjs"
],
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 2021,
"sourceType": "module"
}
}
]
},
"lint-staged": {
"{gateway,payloads,rest,rpc,voice,utils}/**/*.{mjs,js,ts}": "eslint --fix --ext mjs,js,ts",
"{globals,v*}.ts": "eslint --fix --ext mjs,js,ts"
@@ -197,13 +172,6 @@
]
}
},
"standard-version": {
"skip": {
"changelog": true,
"commit": true,
"tag": true
}
},
"tsd": {
"directory": "tests"
}

View File

@@ -122,7 +122,6 @@ export type GatewayActivityEmoji = Partial<Pick<APIEmoji, 'name' | 'animated'>>
*/
export interface GatewayActivityParty {
id?: string;
// eslint-disable-next-line prettier/prettier
size?: [currentSize: number, maxSize: number];
}

View File

@@ -0,0 +1,43 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/restrict-template-expressions */
import { Octokit } from '@octokit/action';
import { readFile } from 'node:fs/promises';
const packageJson = JSON.parse(await readFile(new URL('../../package.json', import.meta.url), { encoding: 'utf8' }));
const octokit = new Octokit();
const [OWNER, REPOSITORY] = process.env.GITHUB_REPOSITORY.split('/');
console.log('👀 Getting the previous release version');
const previousReleases = await octokit.repos.listReleases({
owner: OWNER,
repo: REPOSITORY,
});
// Releases are sorted from newest to oldest, this should work™
const previousRelease = previousReleases.data.find((release) => !release.draft);
console.log('👀 Previous release version:', previousRelease?.tag_name);
const pullRequestBody = [
'**Please describe the changes this PR makes and why it should be merged:**',
'',
`This pull request bumps discord-api-types from **${previousRelease?.tag_name ?? 'unknown'}** to **${
packageJson.version
}**.`,
'',
'⚠️ **Do not change the commit message when merging. It must stay in the format `chore(release): ...`!**',
'⚠️ Maintainers, make sure everything is alright in this PR before merging it. This is still a beta test, so things may break.',
];
console.log(`🎉 Creating pull request for discord-api-types ${packageJson.version}`);
const pullRequest = await octokit.pulls.create({
base: 'main',
// The format must stay in sync with the one in create-pr-for-release-and-publish.yml
head: `chore/release/${packageJson.version}`,
owner: OWNER,
repo: REPOSITORY,
maintainer_can_modify: true,
title: `chore(release): ${packageJson.version} 🎉`,
body: pullRequestBody.join('\n'),
});
console.log(`✅ Done! Created pull request ${pullRequest.data.html_url}`);

View File

@@ -0,0 +1,62 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/restrict-template-expressions */
import { Octokit } from '@octokit/action';
import { readFile } from 'node:fs/promises';
const packageJson = JSON.parse(await readFile(new URL('../../package.json', import.meta.url), { encoding: 'utf8' }));
const octokit = new Octokit();
const [OWNER, REPOSITORY] = process.env.GITHUB_REPOSITORY.split('/');
console.log('👀 Getting the previous release version');
const previousReleases = await octokit.repos.listReleases({
owner: OWNER,
repo: REPOSITORY,
});
// Releases are sorted from newest to oldest, this should work™
const previousRelease = previousReleases.data.find((release) => !release.draft);
console.log('👀 Previous release version:', previousRelease?.tag_name);
const releaseChangelog = [];
const changelogContent = await readFile(new URL('../../CHANGELOG.md', import.meta.url), { encoding: 'utf8' });
if (previousRelease) {
// find difference between previous release and current version
const maybeMinorIndex = changelogContent.indexOf(`## [${previousRelease.tag_name}](https://github.com`);
if (maybeMinorIndex === -1) {
// find major version
const maybeMajorIndex = changelogContent.indexOf(`# [${previousRelease.tag_name}](https://github.com`);
releaseChangelog.push(changelogContent.slice(0, maybeMajorIndex));
} else {
releaseChangelog.push(changelogContent.slice(0, maybeMinorIndex));
}
} else {
releaseChangelog.push(changelogContent);
}
const { data } = await octokit.repos.generateReleaseNotes({
owner: OWNER,
repo: REPOSITORY,
tag_name: packageJson.version,
});
// Include new contributors
const possibleNewContributors = data.body.indexOf('## New Contributors');
if (possibleNewContributors === -1) {
releaseChangelog.push('', data.body.slice(data.body.indexOf('**Full Changelog**')));
} else {
releaseChangelog.push('', data.body.slice(possibleNewContributors));
}
console.log(`🎉 Creating new release for discord-api-types ${packageJson.version}`);
const release = await octokit.repos.createRelease({
owner: OWNER,
repo: REPOSITORY,
tag_name: packageJson.version,
name: packageJson.version,
body: releaseChangelog.join('\n'),
});
console.log(`✅ Done! Release created at ${release.data.html_url}`);

View File

@@ -0,0 +1,83 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
import { Octokit } from '@octokit/action';
import { execSync } from 'node:child_process';
import { readFile } from 'node:fs/promises';
const octokit = new Octokit();
const [OWNER, REPOSITORY] = process.env.GITHUB_REPOSITORY.split('/');
const commitUrl = `https://github.com/${OWNER}/${REPOSITORY}/commit/${process.env.GITHUB_SHA}`;
/** @type {import('@octokit/webhooks-types').PullRequestOpenedEvent | import('@octokit/webhooks-types').PullRequestSynchronizeEvent} */
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const prEvent = JSON.parse(await readFile(process.env.GITHUB_EVENT_PATH, 'utf8'));
const {
pull_request: {
number,
user: { login },
},
} = prEvent;
console.info(`👀 Verifying that deno types are up to date with commit ${process.env.GITHUB_SHA}`);
console.debug('Running build:deno script');
execSync(`npm run build:deno`);
console.debug('Getting the difference between clone and deno build output.');
const diff = execSync(`git diff --name-only ${process.env.GITHUB_SHA}`)
.toString()
.split('\n')
.filter((line) => line.startsWith('deno/'));
if (!diff.length) {
console.info('✅ Nothing to do here!');
const allReviews = await octokit.pulls.listReviews({
owner: OWNER,
pull_number: number,
repo: REPOSITORY,
});
const lastReviewByBot = allReviews.data.filter((item) => item.user?.id === 41898282).at(-1);
if (lastReviewByBot?.state === 'CHANGES_REQUESTED') {
await octokit.pulls.dismissReview({
owner: OWNER,
repo: REPOSITORY,
pull_number: number,
message: 'No longer applicable as deno types are in sync once again! 🎉',
review_id: lastReviewByBot.id,
});
}
process.exit(0);
}
console.debug(`⚠️ Found ${diff.length} different files.`, { diff });
const messageBody = [
`Hey @${login}! Taking a look at commit ${commitUrl}, it seems that you forgot to run \`npm run build:deno\`. Here are the files that are different from the base:`,
'',
];
for (const file of diff) {
messageBody.push(
`- [Node: \`${file.slice(5)}\`](https://github.com/${process.env.GITHUB_REPOSITORY}/blob/${
process.env.GITHUB_SHA
}/${file.slice(5)}) - [Deno: \`${file}\`](https://github.com/${process.env.GITHUB_REPOSITORY}/blob/${
process.env.GITHUB_SHA
}/${file})`,
);
}
messageBody.push('', 'Please run `npm run build:deno` and commit the results to update the deno types.');
console.info('🔈 Requesting changes in the pull request');
await octokit.pulls.createReview({
event: 'REQUEST_CHANGES',
body: messageBody.join('\n'),
owner: OWNER,
repo: REPOSITORY,
pull_number: number,
});
console.info('✅ Done!');

87
scripts/bump-version.mjs Normal file
View File

@@ -0,0 +1,87 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
import { Octokit } from '@octokit/action';
import conventionalRecommendedBump from 'conventional-recommended-bump';
import { execSync } from 'node:child_process';
import { promisify } from 'node:util';
const octokit = new Octokit();
const [OWNER, REPOSITORY] = process.env.GITHUB_REPOSITORY.split('/');
const lastCommitMessage = execSync('git log -1 --pretty=%B', { encoding: 'utf8' });
if (lastCommitMessage.startsWith('chore(release)')) {
console.log('Preventing the action from completing as there are no new commits to release.');
process.exit(1);
}
const conventionalReleaseTypesTo0Ver = new Map([
['major', 'minor'],
['minor', 'patch'],
['patch', 'patch'],
]);
/** @type {(options: import('conventional-recommended-bump').Options) => Promise<import('conventional-recommended-bump').Callback.Recommendation>} */
const asyncConventionalRecommendBump = promisify(conventionalRecommendedBump);
const result = await asyncConventionalRecommendBump({ preset: 'angular' });
if (!result.releaseType) {
throw new Error('No recommended bump level found');
}
const expectedBumpType = conventionalReleaseTypesTo0Ver.get(result.releaseType);
if (!expectedBumpType) {
throw new Error(`Unexpected release type: ${result.releaseType}`);
}
console.info(` Bumping the ${expectedBumpType} version: ${result.reason}`);
execSync(`npm version ${expectedBumpType}`);
const newVersion = JSON.parse(execSync('npm version --json', { encoding: 'utf8' }));
console.info(
`✅ Done! discord-api-types was bumped to ${newVersion['discord-api-types']}! Checking if there was a pull request open already and closing it if so...`,
);
const pullRequests = await octokit.pulls.list({
owner: OWNER,
repo: REPOSITORY,
state: 'open',
});
const previousPullRequest = pullRequests.data.find(
// Find release PRs made by GitHub actions
({ title, user }) => title.startsWith(`chore(release):`) && user?.id === 41898282,
);
if (previousPullRequest) {
console.log(' Closing previous pull request to re-create it...');
// Warn the PR
await octokit.issues.createComment({
owner: OWNER,
repo: REPOSITORY,
issue_number: previousPullRequest.number,
body: '👀 This pull request will be closed and re-created as there may have been new changes between the commit this pull request was opened for and the latest commit.',
});
// Close the PR
await octokit.pulls.update({
owner: OWNER,
repo: REPOSITORY,
pull_number: previousPullRequest.number,
state: 'closed',
});
// Delete the branch
// https://github.community/t/how-to-delete-a-branch-through-the-api/211792
await octokit.request('DELETE /repos/{owner}/{repo}/git/refs/{ref}', {
owner: OWNER,
repo: REPOSITORY,
ref: `heads/chore/release/${newVersion['discord-api-types']}`,
});
console.log(`✅ Done. Pull request ${previousPullRequest.number} was closed and will be recreated.`);
}

View File

@@ -32,6 +32,10 @@ function convertImports(source) {
const transformers = [convertImports];
/**
* @param {URL} fullFilePath
* @param {URL} finalDenoPath
*/
async function convertFile(fullFilePath, finalDenoPath) {
const originalFile = await readFile(fullFilePath, { encoding: 'utf8' });

11
scripts/tsconfig.json Normal file
View File

@@ -0,0 +1,11 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true,
"checkJs": true
},
"include": ["./**/*"]
}

View File

@@ -8,6 +8,10 @@ const __dirname = dirname(__filename);
const rootDir = join(__dirname, '..');
const execAsync = promisify(exec);
/**
* @param {string} path
* @param {string} version
*/
const fileToESMWrapperCall = (path, version) =>
execAsync(`npx gen-esm-wrapper "${join(rootDir, path, `${version}.js`)}" "${join(rootDir, path, `${version}.mjs`)}"`);

View File

@@ -1,8 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true
"allowJs": true
},
"include": [
"globals.ts",