Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 20 additions & 23 deletions .github/workflows/test-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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 }}
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/main-tests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { fileURLToPath } from 'url';
import { jest, expect } from '@jest/globals';

import { Configuration, InputType } from '../types';
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 13 additions & 3 deletions src/__tests__/utils-tests.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down