Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/test-ref-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

steps:
- name: Checkout default repository
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Reference branch
id: ref-branch
Expand Down
88 changes: 88 additions & 0 deletions actions/build-test-publish/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Build, test, publish
description: Build, optionally test, and optionally publish to NPM

inputs:
vars:
description: JSON representation of workflow vars object
required: true

runs:
using: composite

steps:
- name: Setup node
uses: actions/setup-node@v6
with:
node-version: ${{ fromJSON(inputs.vars).NODE_VERSION }}
registry-url: https://registry.npmjs.org/

- name: Start terminal session (pre build)
if: fromJSON(inputs.vars).TERMINAL_PRE_BUILD == 'true'
uses: mxschmitt/action-tmate@v3

- name: Build
id: build
shell: bash
run: |
# Get the name property.
name=`grep "^ \"name\": " package.json | cut -d "\"" -f 4 -s`

# Get the version property.
version=`grep "^ \"version\": " package.json | cut -d "\"" -f 4 -s`

# Get the label on the version property if any, minus pre-release identifier if any.
label=`echo $version | cut -d "-" -f 2 -s | cut -d "." -f 1`

# Save the properties for future steps.
echo "name=$name" >> $GITHUB_OUTPUT
echo "version=$version" >> $GITHUB_OUTPUT
echo "label=$label" >> $GITHUB_OUTPUT

npm install

# If version has a label, build in development mode.
if [[ "$label" != "" ]]
then
npm run build:dev
else
npm run build:release
fi

- name: Start terminal session (post build)
if: fromJSON(inputs.vars).TERMINAL_POST_BUILD == 'true'
uses: mxschmitt/action-tmate@v3

- name: Test
shell: bash
run: |
# Run test script if present.
npm run test --if-present

- name: Publish
shell: bash
run: |
name="${{ steps.build.outputs.name }}"
version="${{ steps.build.outputs.version }}"
label="${{ steps.build.outputs.label }}"

# If version has a label, use it as the tag.
if [[ "$label" != "" ]]
then
tag_args="--tag $label"
fi

if [[ "${{ github.event_name }}" != "release" ]]
then
dry_run_arg="--dry-run"
fi

# Create .npmignore to exclude hidden directories.
echo /.\*/ > .npmignore

npm publish --access public $tag_args $dry_run_arg

# If the latest version has the same label as this version, replace with this version.
if [[ "$label" != "" && "$label" = `npm view $name version | cut -d "-" -f 2 -s | cut -d "." -f 1` ]]
then
echo "Run: npm dist-tag add $name@$version latest $dry_run_arg"
fi
7 changes: 7 additions & 0 deletions actions/ref-branch/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Reference branch
description: Parse the GitHub context reference properties to determine the branch on which the workflow is running

inputs:
path:
description: Path to which repository has been checked out
required: false
default: .

outputs:
branch:
description: Fully formed reference of the branch
Expand All @@ -16,6 +22,7 @@ runs:
- name: Reference branch
id: ref-branch
shell: bash
working-directory: ${{ inputs.path }}
run: |
if [[ "${{ github.ref_type }}" = "branch" ]]
then
Expand Down