diff --git a/.github/workflows/test-and-publish.yml b/.github/workflows/test-and-publish.yml index f30b8b9..5ff9e65 100644 --- a/.github/workflows/test-and-publish.yml +++ b/.github/workflows/test-and-publish.yml @@ -10,23 +10,17 @@ on: jobs: version: runs-on: ubuntu-latest - container: - image: codacy/git-version steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 with: fetch-depth: 0 - - name: Fix tar access - run: apk add --update --no-progress tar - - name: Fix git access - run: | - git config --global --add safe.directory /__w/diff2html-cli/diff2html-cli - name: Get next version run: | - export NEXT_VERSION="$(/bin/git-version --folder=$PWD --release-branch=master)" + NEXT_VERSION="$(docker run --rm --volume "${GITHUB_WORKSPACE}:/repo:ro" \ + codacy/git-version /bin/git-version --folder=/repo --release-branch=master)" echo "Next version is ${NEXT_VERSION}" echo "${NEXT_VERSION}" > .version - echo "version=${NEXT_VERSION}" >> $GITHUB_ENV + echo "version=${NEXT_VERSION}" >> "${GITHUB_ENV}" - name: Get next npm tag name run: | if [ "${GITHUB_REF_NAME}" = "master" ]; then @@ -39,10 +33,11 @@ jobs: echo "Next tag is ${PUBLISH_TAG}" echo "${PUBLISH_TAG}" > .tag - name: Upload versions - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v7 with: name: versions if-no-files-found: error + include-hidden-files: true path: | .version .tag @@ -52,13 +47,13 @@ jobs: needs: [version] strategy: matrix: - node-version: [16.x, 18.x, 20.x] + node-version: ['22.23.5', '24.22.3', '26.13.1'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 with: fetch-depth: 0 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v6 with: node-version: ${{ matrix.node-version }} cache: 'yarn' @@ -67,22 +62,24 @@ jobs: node -v yarn -v - name: Install dependencies - run: yarn install --ignore-engines + run: yarn install --frozen-lockfile - name: Build library run: yarn run validate publish: + if: github.event_name != 'pull_request' || !github.event.pull_request.draft runs-on: ubuntu-latest needs: [build] environment: ${{ inputs.environment }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 with: fetch-depth: 0 - name: Download versions - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v8 with: name: versions + path: . - name: Store version run: echo "version=$(cat .version)" >> $GITHUB_ENV - name: Configure Git @@ -94,12 +91,12 @@ jobs: with: repo-token: '${{ secrets.GITHUB_TOKEN }}' tag: '${{ env.version }}' - - name: Install dependencies - run: yarn - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v6 with: registry-url: 'https://registry.npmjs.org' - node-version: '18.x' + node-version: '24.22.3' + - name: Install dependencies + run: yarn install --frozen-lockfile - name: Configure Yarn version env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} @@ -118,9 +115,9 @@ jobs: yarn version --non-interactive --new-version $(cat .version) - name: Publish to NPM run: yarn publish --tag $(cat .tag) --non-interactive --new-version $(cat .version) - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v6 with: - node-version: '18.x' + node-version: '24.22.3' registry-url: 'https://npm.pkg.github.com' - name: Configure Yarn version env: diff --git a/src/__tests__/main-tests.ts b/src/__tests__/main-tests.ts index 3612665..e910906 100644 --- a/src/__tests__/main-tests.ts +++ b/src/__tests__/main-tests.ts @@ -1,3 +1,4 @@ +import { fileURLToPath } from 'url'; import { jest, expect } from '@jest/globals'; import { Configuration, InputType } from '../types'; @@ -57,7 +58,7 @@ describe('cli', () => { fileContentToggle: true, formatType: 'html', highlightCode: true, - htmlWrapperTemplate: expect.stringContaining('diff2html-cli/template.html'), + htmlWrapperTemplate: fileURLToPath(new URL('../../template.html', import.meta.url)), ignore: [], inputSource: 'file', outputDestinationFile: undefined, diff --git a/src/__tests__/utils-tests.ts b/src/__tests__/utils-tests.ts index 5ce7a7a..1221dca 100644 --- a/src/__tests__/utils-tests.ts +++ b/src/__tests__/utils-tests.ts @@ -1,14 +1,24 @@ +import { mkdtempSync, rmSync } from 'fs'; +import { tmpdir } from 'os'; +import { join } from 'path'; + import * as utils from '../utils'; const stringToCompare = 'This is a rand0m preTTy string to write and read a file'; describe('utils', () => { test('should write and read file synchronously', () => { - utils.writeFile('/tmp/file.test', stringToCompare); + const fixtureDir = mkdtempSync(join(tmpdir(), 'diff2html-cli-test-')); + try { + const filePath = join(fixtureDir, 'file.test'); + utils.writeFile(filePath, stringToCompare); - const contentRead = utils.readFile('/tmp/file.test'); + const contentRead = utils.readFile(filePath); - expect(stringToCompare).toBe(contentRead); + expect(stringToCompare).toBe(contentRead); + } finally { + rmSync(fixtureDir, { recursive: true, force: true }); + } }); test('should execute command in shell', () => {