From 055c84d7957170dda8579b7233523e89d059d812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sven=20H=C3=BCbner?= Date: Sun, 20 Oct 2024 16:47:14 +0200 Subject: [PATCH] build: add gh actions build --- .github/workflows/commit_gate.yml | 33 +++++++++++++++++++++++ .github/workflows/release.yml | 45 +++++++++++++++++++++++++++++++ src/package.json | 8 +++++- 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/commit_gate.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/commit_gate.yml b/.github/workflows/commit_gate.yml new file mode 100644 index 0000000..392c028 --- /dev/null +++ b/.github/workflows/commit_gate.yml @@ -0,0 +1,33 @@ +name: Commit Gate + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: checkout code + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' # Or any other version you need + + - name: Install dependencies + run: npm ci --prefix src/ + + - name: Build + run: npm run build --prefix src/ + + - name: Install test dependencies + run: npm ci --prefix tests/ + + - name: Run tests + run: npm run test --prefix tests/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a6661d4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,45 @@ +name: Publish npm package + +on: + push: + tags: v* + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + + steps: + - name: Get version from tag + id: get_version + # "refs/tags/v" is 11 characters + run: | + versionNumber=${GITHUB_REF:11} + echo "::set-output name=version_number::$versionNumber" + + - name: checkout code + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org' + + - name: Create npm package + run: | + cd src + npm version ${{ steps.get_version.outputs.version_number }} + npm ci + npm run build + npm pack + + - name: Publish package + run: | + cd src + npm publish --provenance --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/src/package.json b/src/package.json index 778bd21..be081ec 100644 --- a/src/package.json +++ b/src/package.json @@ -3,7 +3,13 @@ "version": "0.0.1", "type": "module", "description": "Validates relations within one or multiple JSON files, such as key, keyref, uniqueness", - "main": "./built/index.js", + "repository": { + "type": "git", + "url": "git+https://github.com/shuebner/json_keyref.git" + }, + "files": [ + "built/" + ], "bin": { "json-keyref": "./built/index.js" },