diff --git a/.github/actions/cached-deps/action.yml b/.github/actions/cached-deps/action.yml index bdb0001..2a7956d 100644 --- a/.github/actions/cached-deps/action.yml +++ b/.github/actions/cached-deps/action.yml @@ -4,7 +4,7 @@ inputs: caching: description: Whether to cache dependencies or not required: false - default: 'true' + default: "true" outputs: used-cache: description: Whether the cache was used @@ -31,9 +31,3 @@ runs: yarn install --frozen-lockfile echo "cache='${{ inputs.caching }}'" >> $GITHUB_OUTPUT shell: bash - - - name: Postinstall - if: steps.cache.outputs.cache-hit == 'true' && inputs.caching == 'true' - id: postinstall - run: yarn postinstall - shell: bash diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..97f18d8 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,78 @@ +name: Build & Publish + +on: + push: + tags: + - "v*" + +permissions: + id-token: write # Required for OIDC + contents: read + packages: write + +jobs: + install-and-build: + name: 🛠️ Install & Build + runs-on: ubuntu-latest + + steps: + - name: 🗜️ Checkout + uses: actions/checkout@v6 + + - name: 🗜️ Setup node version + uses: actions/setup-node@v6 + with: + node-version: 24 + registry-url: "https://registry.npmjs.org" + + - name: 🗜️ Setup Zig + uses: mlugg/setup-zig@v2 + with: + version: 0.15.2 + + - name: 🛠️ Install + uses: ./.github/actions/cached-deps + + - name: 🛠️ Clean temporary files + run: yarn clean + + - name: 📦 Build + run: yarn build + + - name: 🛠️ Setup package + run: yarn script:package-npm + + - name: 🛠️ Copy files to dist + run: yarn copy-files + + - name: 🚀 Publish NPM + if: startsWith(github.ref, 'refs/tags/v') && contains(github.ref, 'beta') == false + run: cd dist && npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + + - name: 🚀 Publish NPM BETA + if: startsWith(github.ref, 'refs/tags/v') && contains(github.ref, 'beta') == true + run: cd dist && npm publish --tag beta + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + + - name: 🛠️ Set up package for GPR + if: startsWith(github.ref, 'refs/tags/v') && contains(github.ref, 'beta') == false + run: yarn script:package-github + + - name: 🛠️ Use GPR + if: startsWith(github.ref, 'refs/tags/v') && contains(github.ref, 'beta') == false + uses: actions/setup-node@v4 + with: + node-version: 24 + registry-url: https://npm.pkg.github.com/ + scope: "@celtian" + + - name: 🚀 Publish to GitHub Package Registry + if: startsWith(github.ref, 'refs/tags/v') && contains(github.ref, 'beta') == false + run: | + cd dist + npm publish + env: + NODE_AUTH_TOKEN: ${{github.token}} diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..42dce93 --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,37 @@ +name: Test PR +"on": pull_request + +jobs: + install-and-test: + name: 🛠️ Install & Test + runs-on: ubuntu-latest + + steps: + - name: 🗜️ Checkout + uses: actions/checkout@v6 + + - name: 🗜️ Setup node version + uses: actions/setup-node@v6 + with: + node-version: 24 + registry-url: "https://registry.npmjs.org" + + - name: 🗜️ Setup Zig + uses: mlugg/setup-zig@v2 + with: + version: 0.15.2 + + - name: 🛠️ Install + uses: ./.github/actions/cached-deps + + - name: 🛠️ Clean temporary files + run: yarn clean + + - name: 📦 Build + run: yarn build + + - name: 🛠️ Setup package + run: yarn script:package-npm + + - name: 🛠️ Copy files to dist + run: yarn copy-files diff --git a/scripts/package-github.ts b/scripts/package-github.ts index e385a0a..6fc1fa6 100644 --- a/scripts/package-github.ts +++ b/scripts/package-github.ts @@ -1,4 +1,4 @@ -import { writeFileSync } from 'fs-extra'; +import { ensureDirSync, writeFileSync } from 'fs-extra'; import { join, resolve } from 'path'; const pkg = require(resolve(__dirname, '..', 'package.json')); @@ -17,6 +17,8 @@ pkg.publishConfig = { registry: 'https://npm.pkg.github.com' }; -writeFileSync(join(__dirname, '..', 'dist', 'package.json'), JSON.stringify(pkg, null, 2)); +const distDir = join(__dirname, '..', 'dist'); +ensureDirSync(distDir); +writeFileSync(join(distDir, 'package.json'), JSON.stringify(pkg, null, 2)); console.log('\x1b[34m', `Package.json in dist/ modified with publishConfig and name.`, '\x1b[0m'); diff --git a/scripts/package-npm.ts b/scripts/package-npm.ts index 36e91fa..5971425 100644 --- a/scripts/package-npm.ts +++ b/scripts/package-npm.ts @@ -1,4 +1,4 @@ -import { writeFileSync } from 'fs-extra'; +import { writeFileSync, ensureDirSync } from 'fs-extra'; import { join, resolve } from 'path'; const pkg = require(resolve(__dirname, '..', 'package.json')); @@ -12,7 +12,9 @@ pkg.bin = { "version-info": "bin/version_info" }; -writeFileSync(join(__dirname, '..', 'dist', 'package.json'), JSON.stringify(pkg, null, 2)); +const distDir = join(__dirname, '..', 'dist'); +ensureDirSync(distDir); +writeFileSync(join(distDir, 'package.json'), JSON.stringify(pkg, null, 2)); console.log('\x1b[34m', 'Package.json in dist/ modified.', '\x1b[0m');