diff --git a/.backstage/changelog.cjs b/.backstage/changelog.cjs deleted file mode 100644 index bccb8b5..0000000 --- a/.backstage/changelog.cjs +++ /dev/null @@ -1,56 +0,0 @@ -const fs = require("fs"); -const path = require("path"); - -const version = process.env.GIT_VERSION; -const changelogFile = path.join(__dirname, "../CHANGELOG.md"); -const releaseFile = path.join(__dirname, "../RELEASE.md"); - -const err = (m) => { - console.error(m); - process.exit(1); -} - -const date = () => { - let options = { year: 'numeric', month: 'long', day: 'numeric' }; - return new Date().toLocaleString('en-US', options); -} - -if (!version) err("Script expected a GIT_VERSION environment variable"); - -if (!fs.existsSync(changelogFile)) err(`Script expected a file at ${changelogFile}`); - -let contents = fs.readFileSync(changelogFile, { encoding: "utf-8" }); -let release = [], lines = contents.split(/\n/g); -let it = lines.entries(); - -while (!(entry = it.next()).done) { - let [num, line] = entry.value; - // Read until we reach our unreleased changelog section. - if (/^\s*## Unreleased\s*$/.test(line)) { - let releaseHeader = `## v${version} (${date()})`; - lines[num] = `## Unreleased\n\n${releaseHeader}`; - break; - } -} - - -while (!(entry = it.next()).done) { - let [, line] = entry.value; - // Read until we reach the section for a new version. - if (/^\s*##\s+v/i.test(line)) { - break; - } - release.push(line); -} - -if (!release.some((v => v.trim().length))) { - err([ - `No unreleased changes exist in ${changelogFile}.`, - `Cancelling release — please write release notes!` - ].join('\n')); -} - -if (process.argv[2] === "write") { - fs.writeFileSync(releaseFile, release.join('\n')); - fs.writeFileSync(changelogFile, lines.join('\n')); -} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ed26dbd..383eea5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -52,38 +52,9 @@ jobs: NPM_TAG=$(node ./.backstage/get_npm_tag.cjs) echo NPM_TAG="$NPM_TAG" >> $GITHUB_ENV - - name: Build CHANGELOG - if: env.NPM_TAG == 'latest' - run: | - node ./.backstage/changelog.cjs write - echo CHANGELOG=\"$(base64 -w 0 -i CHANGELOG.md)\" >> $GITHUB_ENV - echo SHA=\"$( git rev-parse main:CHANGELOG.md )\" >> $GITHUB_ENV - - name: Build CHANGELOG - if: env.NPM_TAG != 'latest' - run: | - echo "## Prerelease" > RELEASE.md - node ./.backstage/changelog.cjs write || true - - - name: Commit new CHANGELOG - uses: octokit/request-action@v2.x - if: env.NPM_TAG == 'latest' - id: push_changes - with: - route: PUT /repos/{owner}/{repo}/contents/CHANGELOG.md - owner: cloudcannon - repo: gadget - branch: main - message: Changelog for ${{ env.GIT_VERSION }} - sha: ${{ env.SHA }} - content: ${{ env.CHANGELOG }} - env: - GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }} - - name: Stable Release uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') && env.NPM_TAG == 'latest' - with: - body_path: RELEASE.md env: GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }} @@ -91,7 +62,6 @@ jobs: uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') && env.NPM_TAG != 'latest' with: - body_path: RELEASE.md prerelease: true env: GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }} @@ -111,18 +81,27 @@ jobs: run: | NPM_TAG=$(node ./.backstage/get_npm_tag.cjs) echo NPM_TAG="$NPM_TAG" >> $GITHUB_ENV - + - name: Prepare package run: | - npm version $GIT_VERSION + npm --no-git-tag-version version $GIT_VERSION - name: Install run: npm ci - name: Build run: npm run build - - - name: Publish - run: npm publish --tag $NPM_TAG - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Publish internal + uses: JS-DevTools/npm-publish@v3 + with: + tag: ${{ env.NPM_TAG }} + token: ${{ secrets.GITHUB_TOKEN }} + registry: "https://npm.pkg.github.com" + + - name: Publish external + uses: JS-DevTools/npm-publish@v3 + with: + tag: ${{ env.NPM_TAG }} + token: ${{ secrets.NPM_TOKEN }} + access: public