@firefoxic/utils 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/getProjectRoot.js +22 -0
- package/lib/index.js +2 -0
- package/lib/updateChangelog.js +7 -2
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { env } from "node:process"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get the path to the project root when deploying to GitHub Pages.
|
|
5
|
+
* Your action should set `REPO_NAME` and `REPO_NAME` environment variables at the step you need
|
|
6
|
+
* (most likely when building the project), for example like this:
|
|
7
|
+
*
|
|
8
|
+
* - name: Build project
|
|
9
|
+
* run: pnpm build
|
|
10
|
+
* env:
|
|
11
|
+
* REPO_NAME: ${{ github.event.repository.name }}
|
|
12
|
+
* PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
13
|
+
*
|
|
14
|
+
* @returns {string} The path to the project directory from the domain root if working in a GitHub CI environment. If not, returns `/`.
|
|
15
|
+
*/
|
|
16
|
+
export function getProjectRoot () {
|
|
17
|
+
if (!env.CI || !env.REPO_NAME) { return `` }
|
|
18
|
+
|
|
19
|
+
if (!env.PR_NUMBER) { return `/${env.REPO_NAME}` }
|
|
20
|
+
|
|
21
|
+
return `/${env.REPO_NAME}/${env.PR_NUMBER}`
|
|
22
|
+
}
|
package/lib/index.js
CHANGED
package/lib/updateChangelog.js
CHANGED
|
@@ -81,7 +81,12 @@ function updateChangelogLinks (content, newVersion) {
|
|
|
81
81
|
if (!linkMatch) throw new Error(`Invalid CHANGELOG.md: [Unreleased] link syntax is incorrect.`)
|
|
82
82
|
|
|
83
83
|
const previousVersion = linkMatch[2]
|
|
84
|
-
const
|
|
84
|
+
const existingVersionRegex = new RegExp(`\\[${previousVersion}\\]:`)
|
|
85
|
+
const newVersionLinkPath = content.match(existingVersionRegex)
|
|
86
|
+
? `${linkMatch[1]}${previousVersion}...v${newVersion}`
|
|
87
|
+
: `${linkMatch[1].replace(`compare`, `releases/tag`)}${newVersion}`
|
|
85
88
|
|
|
86
|
-
|
|
89
|
+
const newLinks = `${linkMatch[1]}${newVersion}${linkMatch[3]}\n[${newVersion}]${newVersionLinkPath}`
|
|
90
|
+
|
|
91
|
+
return content.replace(linkRegex, newLinks)
|
|
87
92
|
}
|