devops/.forgejo/actions/build-node-app/action.yaml

84 lines
2.2 KiB
YAML

name: Verify package.json version
description: This action build a nodejs app, and run the tests
inputs:
test_action:
description: Name of the test script
default: test
required: false
build_context:
description: Build context directory (absolute or relative to GITHUB_WORKSPACE)
default: .
required: false
build_action:
description: Name of the build script
default: build
required: false
build_path:
description: Path of the build output
default: dist
required: false
artifact_name:
description: Name for the generated artifact
default: dist
required: false
should_zip_artifact:
description: Whether to zip the artifact before uploading
default: "false"
required: false
runs:
using: composite
steps:
- name: Build-Node-App Install dependencies
shell: sh
run: apk add nodejs tar
- name: Build-Node-App_Git Clone
uses: actions/checkout@v4
- name: Build-Node-App Restore Node Modules Cache
uses: actions/cache@v5
with:
path: ~/.npm
key: ${{ runner.os }}-nodejs-${{ hashFiles('package-lock.json') }}
- name: Build-Node-App Build and Test
shell: sh
run: |
cd ${{ inputs.build_context }}
npm install
npm run ${{ inputs.test_action }}
npm run ${{ inputs.build_action }}
- name: Zip Artifact
if: ${{ inputs.should_zip_artifact == 'true' }}
shell: sh
run: |
tar -czf ${{ inputs.artifact_name }}.tar.gz -C ${{ inputs.build_path }} .
echo "Artifact zipped: ${{ inputs.artifact_name }}.tar.gz"
- name: Store Node Modules Cache
uses: actions/cache/save@v5
with:
path: ~/.npm
key: ${{ runner.os }}-nodejs-${{ hashFiles('package-lock.json') }}
- uses: actions/upload-artifact@v3
if: ${{ inputs.should_zip_artifact == 'false' }}
name: Build-Node-App Upload Artifact
with:
name: ${{ inputs.artifact_name }}
path: ${{ inputs.build_path }}
- uses: actions/upload-artifact@v3
if: ${{ inputs.should_zip_artifact == 'true' }}
name: Build-Node-App Upload Zipped Artifact
with:
name: ${{ inputs.artifact_name }}
path: ${{ inputs.artifact_name }}.tar.gz