diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 13e4144..73d0cbe 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -14,10 +14,10 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: "20" cache: "npm" @@ -41,45 +41,61 @@ jobs: if: github.ref == 'refs/heads/master' && github.event_name == 'push' needs: build runs-on: ubuntu-latest - # create a current_version variable that can be used in the next steps - outputs: - current_version: ${{ steps.version_check.outputs.current_version }} steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: "20" cache: "npm" + registry-url: "https://registry.npmjs.org" - name: Install dependencies run: npm install - - name: Build Talkr - run: npm run build - # fetch the latest release tag and compare it to the current package.json version - # publish if the version has been bumped - # if there is no tag (first release), the previous version is set to "none" and the publish step continues - name: Check if package version has been bumped id: version_check - run: | - current_version=$(jq -r '.version' package.json) - echo "current_version=$current_version" >> $GITHUB_ENV - git fetch --tags - previous_version=$(git tag --sort=-v:refname | head -n 1 || echo "none") - echo "previous_version=$previous_version" >> $GITHUB_ENV - if [ "$previous_version" != "none" ] && [ "$previous_version" == "v$current_version" ]; then - echo "Version has not been bumped. Exiting." - exit 1 - fi + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const core = require('@actions/core'); + const { execSync } = require('child_process'); + + // Read the current version from package.json + const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); + const currentVersion = packageJson.version; + + // Fetch the latest tags + execSync('git fetch --tags'); + + // Get the latest tag + let allTags = execSync('git tag -l --sort=v:refname').toString().trim().split('\n') + let previousVersion = allTags[0]; + if (!previousVersion) { + previousVersion = 'none'; + } else { + previousVersion = previousVersion.replace(/^v/, ''); // Remove the 'v' prefix if present + } + + // Check if the version has been bumped + if (previousVersion === currentVersion || currentVersion === '') { + console.log('Version has not been bumped. Exiting.'); + process.exit(1); + } + + // Set outputs for the next steps + core.setOutput('current_version', currentVersion); + + - name: Log current version + run: echo "The current version is ${{ steps.version_check.outputs.current_version }}" - name: Publish to npm - if: ${{ steps.version_check.outputs.current_version != '' }} env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: npm publish --access=public - name: Create GitHub Release diff --git a/package-lock.json b/package-lock.json index 9bfd6a0..4f4b7ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "3.4.1", "license": "ISC", "devDependencies": { + "@actions/core": "^1.10.1", "@babel/preset-env": "^7.25.3", "@babel/preset-react": "^7.24.7", "@eslint/js": "^9.9.0", @@ -37,6 +38,26 @@ "typescript-eslint": "^8.2.0" } }, + "node_modules/@actions/core": { + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.1.tgz", + "integrity": "sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g==", + "dev": true, + "dependencies": { + "@actions/http-client": "^2.0.1", + "uuid": "^8.3.2" + } + }, + "node_modules/@actions/http-client": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.2.tgz", + "integrity": "sha512-2TvX5LskKQzDDQI+bobIDGAjkn0NJiQlg4MTrKnZ8HfQ7nDEUbtJ1ytxPDb2bfk3Hr2XD99X8oAJISAmIoiSAQ==", + "dev": true, + "dependencies": { + "tunnel": "^0.0.6", + "undici": "^5.25.4" + } + }, "node_modules/@adobe/css-tools": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.4.0.tgz", @@ -1985,6 +2006,15 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@fastify/busboy": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", + "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==", + "dev": true, + "engines": { + "node": ">=14" + } + }, "node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", @@ -10694,6 +10724,15 @@ "integrity": "sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==", "dev": true }, + "node_modules/tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", + "dev": true, + "engines": { + "node": ">=0.6.11 <=0.7.0 || >=0.7.3" + } + }, "node_modules/type-check": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", @@ -10851,6 +10890,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/undici": { + "version": "5.28.4", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.4.tgz", + "integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==", + "dev": true, + "dependencies": { + "@fastify/busboy": "^2.0.0" + }, + "engines": { + "node": ">=14.0" + } + }, "node_modules/unicode-canonical-property-names-ecmascript": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", @@ -10949,6 +11000,15 @@ "requires-port": "^1.0.0" } }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "dev": true, + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/v8-to-istanbul": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz", diff --git a/package.json b/package.json index e009bfe..24453fb 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/DoneDeal0/Talkr" + "url": "git+https://github.com/DoneDeal0/Talkr.git" }, "keywords": [ "i18n", @@ -40,6 +40,7 @@ "author": "DoneDeal0", "license": "ISC", "devDependencies": { + "@actions/core": "^1.10.1", "@babel/preset-env": "^7.25.3", "@babel/preset-react": "^7.24.7", "@eslint/js": "^9.9.0", diff --git a/yarn.lock b/yarn.lock index 87b90e3..05826b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,22 @@ # yarn lockfile v1 +"@actions/core@^1.10.1": + version "1.10.1" + resolved "https://registry.npmjs.org/@actions/core/-/core-1.10.1.tgz" + integrity sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g== + dependencies: + "@actions/http-client" "^2.0.1" + uuid "^8.3.2" + +"@actions/http-client@^2.0.1": + version "2.2.2" + resolved "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.2.tgz" + integrity sha512-2TvX5LskKQzDDQI+bobIDGAjkn0NJiQlg4MTrKnZ8HfQ7nDEUbtJ1ytxPDb2bfk3Hr2XD99X8oAJISAmIoiSAQ== + dependencies: + tunnel "^0.0.6" + undici "^5.25.4" + "@adobe/css-tools@^4.4.0": version "4.4.0" resolved "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.4.0.tgz" @@ -1061,6 +1077,11 @@ resolved "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.4.tgz" integrity sha512-BsWiH1yFGjXXS2yvrf5LyuoSIIbPrGUWob917o+BTKuZ7qJdxX8aJLRxs1fS9n6r7vESrq1OUqb68dANcFXuQQ== +"@fastify/busboy@^2.0.0": + version "2.1.1" + resolved "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz" + integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA== + "@humanwhocodes/module-importer@^1.0.1": version "1.0.1" resolved "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz" @@ -5068,6 +5089,11 @@ tslib@^2.4.0: resolved "https://registry.npmjs.org/tslib/-/tslib-2.6.3.tgz" integrity sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ== +tunnel@^0.0.6: + version "0.0.6" + resolved "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz" + integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg== + type-check@^0.4.0, type-check@~0.4.0: version "0.4.0" resolved "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz" @@ -5160,6 +5186,13 @@ unbox-primitive@^1.0.2: has-symbols "^1.0.3" which-boxed-primitive "^1.0.2" +undici@^5.25.4: + version "5.28.4" + resolved "https://registry.npmjs.org/undici/-/undici-5.28.4.tgz" + integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g== + dependencies: + "@fastify/busboy" "^2.0.0" + unicode-canonical-property-names-ecmascript@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz" @@ -5216,6 +5249,11 @@ url-parse@^1.5.3: querystringify "^2.1.1" requires-port "^1.0.0" +uuid@^8.3.2: + version "8.3.2" + resolved "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz" + integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== + v8-to-istanbul@^9.0.1: version "9.3.0" resolved "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz"