-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (83 loc) · 3.16 KB
/
ci.yml
File metadata and controls
95 lines (83 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
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
echo pkg=$(jq -r '(.engines | select(.pnpm != null) | "pnpm") // (.engines | select(.yarn != null) | "yarn") // "npm"' ./package.json) >> $GITHUB_OUTPUT
- 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
env:
TOKEN: '${{ secrets.DAN_TOKEN }}'
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 }}