Add actionVersion test

This commit is contained in:
Luis Blanco 2023-01-03 22:55:49 +04:00
parent fd165d935d
commit 3d02cfb49c
4 changed files with 148 additions and 102 deletions

View File

@ -1,16 +1,10 @@
name: Publish name: Publish to NPM
defaults:
run:
shell: bash
on: on:
workflow_dispatch: workflow_dispatch
inputs:
name:
description: 'Release name'
required: true
default: 'Minor Update'
text:
description: 'Patch notes'
required: true
default: Fixed minor issues.
jobs: jobs:
Publish: Publish:
@ -20,16 +14,19 @@ jobs:
steps: steps:
- name: Fetch Repository - name: Fetch Repository
uses: actions/checkout@v2 uses: actions/checkout@v3
with:
persist-credentials: false
- name: Install Node.js - name: Install Node.js
uses: actions/setup-node@v1 uses: actions/setup-node@v3
with: with:
node-version: 18.12.1 node-version: 18.12.1
cache: 'npm'
- name: Get Npm Version - name: Get Package Version
id: package-version id: package-version
uses: martinbeentjes/npm-get-version-action@master run: node -e \"require('./utils').actionVersion()\" >> $GITHUB_OUTPUT
- name: Publish - name: Publish
run: | run: |
@ -38,11 +35,12 @@ jobs:
env: env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: GitHub Release - name: Create Release
uses: actions/create-release@v1 id: create_release
uses: softprops/action-gh-release@v1
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
tag_name: ${{ steps.package-version.outputs.current-version }} tag_name: ${{ steps.package-version.outputs.version }}
release_name: ${{ github.event.inputs.name }} name: Release ${{ steps.package-version.outputs.version }}
body: ${{ github.event.inputs.text }} body: Published at ${{ github.sha }}

View File

@ -1,4 +1,7 @@
name: Validate name: Validate
defaults:
run:
shell: bash
on: on:
push: push:

34
utils.d.ts vendored
View File

@ -42,6 +42,40 @@ declare module "addon-tools-raub/utils" {
export const cpbin: (name: string) => Promise<void>; export const cpbin: (name: string) => Promise<void>;
/**
* Package version for GitHub Actions
* Example of `actionVersion` usage in **Github Actions**:
*
* ```
* - name: Get Package Version
* id: package-version
* run: node -e \"require('addon-tools-raub/utils').actionVersion()\" >> $GITHUB_OUTPUT
* - name: Create Release
* uses: softprops/action-gh-release@v1
* with:
* tag_name: ${{ steps.package-version.outputs.version }}
* ```
*/
export const actionVersion: () => void;
/**
* Package version for GitHub Actions
* Example of `actionZip` usage in **Github Actions**:
*
* ```
* - name: Zip Files
* id: zip-files
* run: node action-zip >> $GITHUB_OUTPUT
* - name: Store Binaries
* uses: softprops/action-gh-release@v1
* with:
* files: ${{ steps.zip-files.outputs.zip }}
* ```
*/
export const actionZip: () => void;
/** /**
* Download to memory * Download to memory
* Accepts an **URL**, and returns an in-memory file Buffer, * Accepts an **URL**, and returns an in-memory file Buffer,

View File

@ -1,6 +1,10 @@
'use strict'; 'use strict';
const util = require('node:util');
const exec = util.promisify(require('node:child_process').exec);
const utils = require('.'); const utils = require('.');
const packageJson = require('../package.json');
describe('utils.js', () => { describe('utils.js', () => {
@ -12,8 +16,15 @@ describe('utils.js', () => {
]; ];
methods.forEach((name) => { methods.forEach((name) => {
it('is a function', () => { it(`exports the "${name}" function`, () => {
expect(typeof utils[name]).toBe('function'); expect(typeof utils[name]).toBe('function');
}); });
}); });
describe('actionVersion', () => {
it('logs package version', async () => {
const { stdout } = await exec('node -e "require(\'./utils\').actionVersion()"');
expect(stdout).toBe(`version=${packageJson.version}`);
});
});
}); });