From c89740d3e2dd9ded886039815c9ec570eb38522d Mon Sep 17 00:00:00 2001 From: John McBride Date: Fri, 1 Sep 2023 11:08:01 -0600 Subject: [PATCH] feat: Adds SKIP_NPM_PUBLISH and SKIP_DOCKER_PUBLISH This enables general usage of this semantic-release system (like in a go app) Signed-off-by: John McBride --- README.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++ release.config.js | 50 ++++++++++++++++++----------------- 2 files changed, 93 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 5e63b1e..8232b7b 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,72 @@ Now all you need to do is create a release: npx semantic-release ``` +## 🏗️ GitHub general usage + +If you do not plan to publish to `npm` _or_ `ghcr` but still want to cut tags +and GitHub releases with this system, you can specify `SKIP_NPM_PUBLISH` and +`SKIP_DOCKER_PUBLISH`. This will still publish releases, generate semver tags, +and generate GitHub release notes. But it will skip attempting to publish + +Then, in a separate GitHub action, you can watch for the releases and upload assets +manually. For example, when building a Go application: + +```yaml +name: Semantic release + +on: + push: + branches: + - main + - beta + workflow_dispatch: + +jobs: + release: + name: Semantic release + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: "☁️ checkout repository" + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: "🚀 release" + id: semantic-release + env: + GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} + SKIP_NPM_PUBLISH: true + SKIP_DOCKER_PUBLISH: true + uses: open-sauced/release@v2 + + outputs: + release-tag: ${{ steps.semantic-release.outputs.release-tag }} + + build: + needs: + - release + runs-on: ubuntu-latest + permissions: + contents: write # release changes require contents write + + steps: + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.21 + + - name: Check out code + uses: actions/checkout@v3 + + - name: Build and upload Go binaries + env: + GH_TOKEN: ${{ github.token }} + run: | + go build -o build/my-go-binary + gh release upload ${{ needs.release.outputs.release-tag }} build/my-go-binary +``` + ## 🔧 Configuration See each [plugin](#-plugins) documentation for required installation and configuration steps. diff --git a/release.config.js b/release.config.js index 03b12f9..9189673 100644 --- a/release.config.js +++ b/release.config.js @@ -118,11 +118,13 @@ addPlugin("@semantic-release/changelog", { > All notable changes to this project will be documented in this file` }); -const pkgRoot = NPM_PACKAGE_ROOT || "."; -addPlugin("@semantic-release/npm", { - tarballDir: "pack", - pkgRoot, -}); +if (process.env.SKIP_NPM_PUBLISH === undefined) { + const pkgRoot = NPM_PACKAGE_ROOT || "."; + addPlugin("@semantic-release/npm", { + tarballDir: "pack", + pkgRoot, + }); +} const actionExists = existsSync("./action.yml"); if (actionExists) { @@ -164,23 +166,25 @@ if (manifestExists && GITHUB_REF === "refs/heads/main") { }); } -const packageFilesPrefix = process.env.NPM_PACKAGE_ROOT ? `${process.env.NPM_PACKAGE_ROOT}/` : ""; -addPlugin("@semantic-release/git", { - "assets": [ - "LICENSE*", - "CHANGELOG.md", - `${packageFilesPrefix}package.json`, - `${packageFilesPrefix}package-lock.json`, - `${packageFilesPrefix}npm-shrinkwrap.json`, - `${packageFilesPrefix}yarn.lock`, - `${packageFilesPrefix}pnpm-lock.yaml`, - "public/**/*", - "supabase/**/*", - "action.yml", - "manifest.json" - ], - "message": `chore(<%= nextRelease.type %>): release <%= nextRelease.version %> <%= nextRelease.channel !== null ? \`on \${nextRelease.channel} channel \` : '' %>[skip ci]\n\n<%= nextRelease.notes %>` -}); +if (process.env.SKIP_NPM_PUBLISH === undefined) { + const packageFilesPrefix = process.env.NPM_PACKAGE_ROOT ? `${process.env.NPM_PACKAGE_ROOT}/` : ""; + addPlugin("@semantic-release/git", { + "assets": [ + "LICENSE*", + "CHANGELOG.md", + `${packageFilesPrefix}package.json`, + `${packageFilesPrefix}package-lock.json`, + `${packageFilesPrefix}npm-shrinkwrap.json`, + `${packageFilesPrefix}yarn.lock`, + `${packageFilesPrefix}pnpm-lock.yaml`, + "public/**/*", + "supabase/**/*", + "action.yml", + "manifest.json" + ], + "message": `chore(<%= nextRelease.type %>): release <%= nextRelease.version %> <%= nextRelease.channel !== null ? \`on \${nextRelease.channel} channel \` : '' %>[skip ci]\n\n<%= nextRelease.notes %>` + }); +} addPlugin("@semantic-release/github", { "addReleases": "bottom", @@ -193,7 +197,7 @@ addPlugin("@semantic-release/github", { }); const dockerExists = existsSync("./Dockerfile"); -if (dockerExists) { +if (dockerExists && process.env.SKIP_DOCKER_PUBLISH === undefined) { addPlugin("eclass-docker-fork", { "baseImageName": `${owner}/${repo}`, "registries": [