-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
87 additions
and
5 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 |
---|---|---|
|
@@ -56,19 +56,34 @@ jobs: | |
- uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: v1.x | ||
- id: determine-version | ||
run: deno run -A scripts/determine-version.ts | ||
- if: github.ref_type == 'tag' | ||
run: '[[ "$VERSION" = "$GITHUB_REF_NAME" ]]' | ||
env: | ||
VERSION: ${{ steps.determine-version.outputs.version }} | ||
- run: deno install -Af --unstable https://x.nest.land/[email protected]/eggs.ts | ||
- run: "eggs link '${{ secrets.NEST_API_KEY }}'" | ||
- if: github.ref_type == 'tag' | ||
uses: mikefarah/yq@master | ||
with: | ||
cmd: >- | ||
yq -i | ||
' strenv(GITHUB_REF_NAME) as $version | ||
| .version = $version | ||
| .unstable = false' | ||
egg.yaml | ||
- if: github.ref_type != 'tag' | ||
uses: mikefarah/yq@master | ||
with: | ||
cmd: >- | ||
yq -i | ||
' strenv(GITHUB_RUN_NUMBER) as $run-number | ||
| strenv(GITHUB_SHA) as $sha | ||
| .version = .version + "-dev." + $run-number + "+" + $sha | ||
| .version |= (match("^[^+]+\+[a-f0-9]{7}") | .string) | ||
' strenv(VERSION) as $version | ||
| .version = $version | ||
| .unstable = true' | ||
egg.yaml | ||
env: | ||
VERSION: ${{ steps.determine-version.outputs.version }} | ||
- run: | | ||
# Try up to 3 times as `eggs publish` frequently fails due to unknown | ||
# reason (I guess it's a bug on the server side): | ||
|
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 |
---|---|---|
|
@@ -2,7 +2,6 @@ $schema: https://x.nest.land/[email protected]/src/schema.json | |
name: aitertools | ||
description: Well-tested utility functions dealing with async iterables | ||
homepage: https://github.com/dahlia/aitertools | ||
version: 0.5.0 | ||
releaseType: null | ||
unstable: false | ||
unlisted: false | ||
|
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,68 @@ | ||
import { | ||
dirname, | ||
fromFileUrl, | ||
join, | ||
} from "https://deno.land/[email protected]/path/mod.ts"; | ||
import * as commonmark from "npm:commonmark"; | ||
|
||
const projectDir = dirname(dirname(fromFileUrl(import.meta.url))); | ||
const changelogPath = join(projectDir, "CHANGES.md"); | ||
|
||
function findTopmostVersion(node: typeof commonmark.Node): string { | ||
const walker = node.walker(); | ||
while (true) { | ||
const event = walker.next(); | ||
if (!event) break; | ||
const node = event.node; | ||
if ( | ||
node.type == "heading" && node.level == 2 && | ||
node.firstChild.type == "text" && | ||
node.firstChild.literal.startsWith("Version") | ||
) { | ||
return node.firstChild.literal.replace(/^Version\s+/, "").trim(); | ||
} | ||
} | ||
|
||
throw new Error("Version not found"); | ||
} | ||
|
||
async function findLatestVersionFromChangelog(path: string): Promise<string> { | ||
const parser = new commonmark.Parser(); | ||
const text = await Deno.readTextFile(path); | ||
const tree = parser.parse(text); | ||
return findTopmostVersion(tree); | ||
} | ||
|
||
function determineVersionSuffix(): string { | ||
const runNo = Deno.env.get("GITHUB_RUN_NUMBER"); | ||
const commitSha = Deno.env.get("GITHUB_SHA"); | ||
return `dev.${runNo}+${commitSha?.substring(0, 7)}`; | ||
} | ||
|
||
async function output(name: string, value: string): Promise<void> { | ||
const outputPath = Deno.env.get("GITHUB_OUTPUT"); | ||
if (Deno.env.get("GITHUB_ACTIONS") === "true" && outputPath != null) { | ||
const escaped = value | ||
.replace(/%/g, "%25") | ||
.replace(/\r/g, "%0D") | ||
.replace(/\n/g, "%0A"); | ||
await Deno.writeTextFile(outputPath, `${name}=${escaped}\n`); | ||
} else { | ||
console.log(value); | ||
} | ||
} | ||
|
||
async function main() { | ||
const baseVersion = await findLatestVersionFromChangelog(changelogPath); | ||
if ( | ||
Deno.env.get("GITHUB_ACTIONS") === "true" && | ||
Deno.env.get("GITHUB_REF_TYPE") === "branch" | ||
) { | ||
const version = `${baseVersion}-${determineVersionSuffix()}`; | ||
await output("version", version); | ||
} else { | ||
await output("version", baseVersion); | ||
} | ||
} | ||
|
||
if (import.meta.main) await main(); |