Skip to content

Build and Deploy

Build and Deploy #63

Workflow file for this run

name: Build and Deploy
on:
create:
push:
branches:
- master
- main
- develop
- dev
- feature/*
- feat/*
- release/*
- hotfix/*
paths:
- '**.js'
- '**.jsx'
- '**.ts'
- '**.tsx'
- '**.json'
release:
types: [published]
jobs:
setup:
if: github.run_number == 1 && github.event_name == 'create'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- name: Initialize
run: |
tmp=$(mktemp)
jq --arg author "${{ github.repository_owner }}" '.author = $author' package.json > $tmp
jq --arg url "git+${{ github.event.repository.clone_url }}" '.repository.url = $url' $tmp > package.json
jq --arg name "${{ github.event.repository.name }}" '.name = $name' package.json > $tmp
jq --arg description "${{ github.event.description }}" '.description = $description' $tmp > package.json
jq --arg homepage "${{ github.event.repository.html_url }}#readme" '.homepage = $homepage' package.json > $tmp
jq --arg bugs "${{ github.event.repository.html_url }}/issues" '.bugs.url = $bugs' $tmp > package.json
echo "# ${{ github.event.repository.name }}" > README.md
rm -rf LICENSE
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Setup project for ${{ github.event.repository.name }} [skip ci]"
ci:
if: github.run_number != 1 && github.event_name != 'create' && !contains(github.event.head_commit.message, '[skip ci]')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# extract `engines.node` from package.json and save it to output
- name: Get Node.JS version from package.json
id: get-versions
run: |
echo node=$(jq -r '.engines.node // "lts/*"' ./package.json) >> $GITHUB_OUTPUT
if [ -f "yarn.lock" ]; then
echo pkg=yarn >> $GITHUB_OUTPUT
elif [ -f "pnpm-lock.yaml" ]; then
echo pkg=pnpm >> $GITHUB_OUTPUT
else
echo pkg=npm >> $GITHUB_OUTPUT
fi
- name: Setup Node.JS
uses: actions/setup-node@v3
with:
node-version: ${{steps.get-versions.outputs.node}}
- name: Setup pnpm
if: steps.get-versions.outputs.pkg == 'pnpm'
uses: pnpm/action-setup@v2
with:
version: latest
- name: Install dependencies
run: ${{steps.get-versions.outputs.pkg}} install
- name: Test
run: ${{steps.get-versions.outputs.pkg}} run test
- name: Build
id: build
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
if: github.event_name == 'release' && env.NPM_TOKEN != null
run: |
${{steps.get-versions.outputs.pkg}} run build
tmp=$(mktemp)
jq --arg version "${{ github.event.release.tag_name }}" '.version = $version' package.json > $tmp
mv $tmp package.json
echo version=$(jq -r '.version' package.json) >> $GITHUB_OUTPUT
- name: Publish
uses: JS-DevTools/npm-publish@v1
if: steps.build.outputs.version != null
with:
token: ${{ secrets.NPM_TOKEN }}