Add actionVersion test
This commit is contained in:
parent
fd165d935d
commit
3d02cfb49c
|
@ -1,16 +1,10 @@
|
|||
name: Publish
|
||||
name: Publish to NPM
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
name:
|
||||
description: 'Release name'
|
||||
required: true
|
||||
default: 'Minor Update'
|
||||
text:
|
||||
description: 'Patch notes'
|
||||
required: true
|
||||
default: Fixed minor issues.
|
||||
workflow_dispatch
|
||||
|
||||
jobs:
|
||||
Publish:
|
||||
|
@ -20,16 +14,19 @@ jobs:
|
|||
steps:
|
||||
|
||||
- name: Fetch Repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18.12.1
|
||||
cache: 'npm'
|
||||
|
||||
- name: Get Npm Version
|
||||
- name: Get Package Version
|
||||
id: package-version
|
||||
uses: martinbeentjes/npm-get-version-action@master
|
||||
run: node -e \"require('./utils').actionVersion()\" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Publish
|
||||
run: |
|
||||
|
@ -38,11 +35,12 @@ jobs:
|
|||
env:
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
- name: GitHub Release
|
||||
uses: actions/create-release@v1
|
||||
- name: Create Release
|
||||
id: create_release
|
||||
uses: softprops/action-gh-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ steps.package-version.outputs.current-version }}
|
||||
release_name: ${{ github.event.inputs.name }}
|
||||
body: ${{ github.event.inputs.text }}
|
||||
tag_name: ${{ steps.package-version.outputs.version }}
|
||||
name: Release ${{ steps.package-version.outputs.version }}
|
||||
body: Published at ${{ github.sha }}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
name: Validate
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
on:
|
||||
push:
|
||||
|
|
|
@ -42,6 +42,40 @@ declare module "addon-tools-raub/utils" {
|
|||
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
|
||||
* Accepts an **URL**, and returns an in-memory file Buffer,
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
const util = require('node:util');
|
||||
const exec = util.promisify(require('node:child_process').exec);
|
||||
|
||||
const utils = require('.');
|
||||
const packageJson = require('../package.json');
|
||||
|
||||
|
||||
describe('utils.js', () => {
|
||||
|
@ -12,8 +16,15 @@ describe('utils.js', () => {
|
|||
];
|
||||
|
||||
methods.forEach((name) => {
|
||||
it('is a function', () => {
|
||||
it(`exports the "${name}" 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}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue