-
Notifications
You must be signed in to change notification settings - Fork 476
Convert last remaining Python CI scripts to TypeScript #4043
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
Open
mbg
wants to merge
18
commits into
main
Choose a base branch
from
mbg/ts/changelog
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2d14f71
Add `NO_CHANGES_STR` constant
mbg 85d1570
Add `prepare-changelog.ts` with tests
mbg b69467c
Update workflows to use `prepare-changelog.ts`
mbg 5901394
Remove `prepare_changelog.py`
mbg 57eb441
Add constant for unreleased placeholder
mbg 093dce6
Add `extractChangelogSnippet` test for the case where there is no fir…
mbg 916098a
Add `parseChangelog` and `renderChangelog`
mbg adba086
Update `processChangelogForBackports` to use `parseChangelog`
mbg c5d6212
Update `extractChangelogSnippet` to use `parseChangelog`
mbg 66a6f42
Add `bundle-changelog.ts` with tests
mbg 027ac05
Use `bundle-changelog.ts` and remove Python version
mbg d714617
Add `rollback-changelog.ts` with tests
mbg 961b583
Use `rollback-changelog.ts` and remove Python version
mbg ab44eb9
Remove `python` from CodeQL workflow
mbg cbad145
Remove Python-specific steps from workflows that no longer need them
mbg 0953dc0
Add `getErrorMessage` to `pr-checks`-local `util.ts` to avoid pulling…
mbg f00f809
Fix checking keys rather than values
mbg 74b15aa
Install JS deps if needed in `post-release-mergeback` workflow
mbg 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 |
|---|---|---|
|
|
@@ -113,7 +113,6 @@ jobs: | |
| matrix: | ||
| include: | ||
| - language: actions | ||
| - language: python | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,142 @@ | ||
| /** | ||
| * Tests for `bundle-changelog.ts`. | ||
| */ | ||
|
|
||
| import * as assert from "node:assert/strict"; | ||
| import * as fs from "node:fs"; | ||
| import * as os from "node:os"; | ||
| import * as path from "node:path"; | ||
| import { afterEach, beforeEach, describe, it } from "node:test"; | ||
|
|
||
| import { | ||
| CLI_VERSION_ENV_VAR, | ||
| getCLIVersion, | ||
| getPRNumber, | ||
| getPRUrl, | ||
| PR_URL_ENV_VAR, | ||
| updateChangelog, | ||
| } from "./bundle-changelog"; | ||
| import { | ||
| EMPTY_CHANGELOG, | ||
| NO_CHANGES_STR, | ||
| UNRELEASED_PLACEHOLDER, | ||
| } from "./changelog"; | ||
|
|
||
| let testDir: string; | ||
|
|
||
| beforeEach(() => { | ||
| // Set up a temporary directory for testing | ||
| testDir = fs.mkdtempSync(path.join(os.tmpdir(), "bundle-changelog-test-")); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| /** Clean up temporary directories. */ | ||
| fs.rmSync(testDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| describe("getCLIVersion", async () => { | ||
| await it("throws if the environment variable is not set", async () => { | ||
| delete process.env[CLI_VERSION_ENV_VAR]; | ||
| assert.throws(() => getCLIVersion()); | ||
| }); | ||
|
|
||
| await it("throws if the environment variable is empty", async () => { | ||
| process.env[CLI_VERSION_ENV_VAR] = " "; | ||
| assert.throws(() => getCLIVersion()); | ||
| }); | ||
|
|
||
| await it("returns value of the environment variable if set", async () => { | ||
| const testValue = "1.2.3"; | ||
| process.env[CLI_VERSION_ENV_VAR] = testValue; | ||
| assert.deepEqual(getCLIVersion(), testValue); | ||
| }); | ||
| }); | ||
|
|
||
| const testPrUrl = "https://github.com/github/codeql-action/pulls/42"; | ||
|
|
||
| describe("getPRUrl", async () => { | ||
| await it("throws if the environment variable is not set", async () => { | ||
| delete process.env[PR_URL_ENV_VAR]; | ||
| assert.throws(() => getPRUrl()); | ||
| }); | ||
|
|
||
| await it("throws if the environment variable is empty", async () => { | ||
| process.env[PR_URL_ENV_VAR] = " "; | ||
| assert.throws(() => getPRUrl()); | ||
| }); | ||
|
|
||
| await it("returns value of the environment variable if set", async () => { | ||
| process.env[PR_URL_ENV_VAR] = testPrUrl; | ||
| assert.deepEqual(getPRUrl(), testPrUrl); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getPRNumber", async () => { | ||
| await it("throws if the last part of the input is not a number", async () => { | ||
| assert.throws(() => getPRNumber(`${testPrUrl}/foo`)); | ||
| }); | ||
|
|
||
| await it("throws if the last part of the input is not a positive number", async () => { | ||
| assert.throws(() => getPRNumber(`${testPrUrl}/-100`)); | ||
| }); | ||
|
|
||
| await it("returns the PR number from an URL", async () => { | ||
| assert.equal(getPRNumber(testPrUrl), 42); | ||
| }); | ||
| }); | ||
|
|
||
| const testChangelog = `${EMPTY_CHANGELOG.trimEnd()} | ||
|
|
||
| ## 4.23.7 | ||
|
|
||
| - Other change | ||
|
|
||
| ## 4.23.6 | ||
|
|
||
| ${NO_CHANGES_STR}`; | ||
|
|
||
| const expectedChangelog = `# CodeQL Action Changelog | ||
|
|
||
| ## ${UNRELEASED_PLACEHOLDER} | ||
|
|
||
| - Update default CodeQL bundle version to | ||
|
|
||
| ## 4.23.7 | ||
|
|
||
| - Other change | ||
|
|
||
| ## 4.23.6 | ||
|
|
||
| ${NO_CHANGES_STR}`; | ||
|
|
||
| describe("updateChangelog", async () => { | ||
| await it("removes `NO_CHANGES_STR` if present in [UNRELEASED] section", async () => { | ||
| const result = updateChangelog(EMPTY_CHANGELOG, ""); | ||
| assert.ok(!result.includes(NO_CHANGES_STR.trim())); | ||
| }); | ||
|
|
||
| await it("doesn't remove `NO_CHANGES_STR` if present in versioned section", async () => { | ||
| const result = updateChangelog( | ||
| EMPTY_CHANGELOG.replace(UNRELEASED_PLACEHOLDER, "1.2.3"), | ||
| "", | ||
| ); | ||
| assert.ok(result.includes(NO_CHANGES_STR.trim())); | ||
| }); | ||
|
|
||
| await it("throws if there are no sections", async () => { | ||
| assert.throws(() => { | ||
| updateChangelog( | ||
| "# CodeQL Action Changelog", | ||
| "- Update default CodeQL bundle version to", | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| await it("adds note at the end of the first section", async () => { | ||
| const result = updateChangelog( | ||
| testChangelog, | ||
| "- Update default CodeQL bundle version to", | ||
| ); | ||
| assert.deepEqual(result, expectedChangelog); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.