-
-
Notifications
You must be signed in to change notification settings - Fork 1
99 lines (89 loc) · 3.04 KB
/
prepare-cli.yml
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
96
97
98
99
name: Prepare CLI tool
run-name: "Prepare CLI tool: ${{ inputs.package }}"
on:
workflow_dispatch:
inputs:
package:
description: '<name>@<version> or <owner>/<repo>#<version>'
type: string
required: true
workflow_call:
inputs:
package:
description: '<name>@<version> or <owner>/<repo>#<version>'
type: string
required: true
outputs:
name:
description: "Package name"
value: ${{ jobs.pack.outputs.name }}
path:
description: "Path to package"
value: ${{ jobs.pack.outputs.source === 'github' && jobs.pack.outputs.tarball || jobs.pack.outputs.name }}
artifact:
description: "Tarball path"
value: ${{ jobs.pack.outputs.tarball }}
jobs:
pack:
runs-on: ubuntu-latest
outputs:
name: ${{ steps.build.outputs.name }}
source: ${{ steps.detect-source.outputs.type }}
tarball: ${{ steps.tgz.outputs.path }}
steps:
- name: Detect source type
id: detect-source
run: |
regex_github='^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+#[A-Za-z0-9_.-]+$'
regex_npm='^(@[a-zA-Z0-9_-]+\/)?[a-zA-Z0-9_-]+(@[a-zA-Z0-9_.-]+)?$'
if [[ ${{ inputs.package }} =~ $regex_github ]]; then
echo "type=github" >> "$GITHUB_OUTPUT"
elif [[ ${{ inputs.package }} =~ $regex_npm ]]; then
echo "type=npm" >> "$GITHUB_OUTPUT"
else
echo 'Cannot determine source type'
exit 1
fi
- name: Print source type
run: |
echo "Source: ${{ steps.detect-source.outputs.type }}"
- name: Extract repo and branch
if: ${{ steps.source-type.outputs.type }} == 'github'
id: repo
run: |
echo "path=$(echo ${{ inputs.package }} | cut -d'#' -f1)" >> "$GITHUB_OUTPUT"
echo "branch=$(echo ${{ inputs.package }} | cut -d'#' -f2)" >> "$GITHUB_OUTPUT"
- name: Clone from GitHub
if: ${{ steps.source-type.outputs.type }} == 'github'
uses: actions/checkout@v2
with:
repository: ${{ steps.repo.outputs.path }}
ref: ${{ steps.repo.outputs.branch }}
token: ${{ secrets.RETE_QA_PUBLIC_PULL }}
fetch-depth: 0
- name: Setup Node.js
if: ${{ steps.source-type.outputs.type }} == 'github'
uses: actions/setup-node@v4
- name: Build
if: ${{ steps.source-type.outputs.type }} == 'github'
id: build
run: |
npm install
npm run build
npm pack
echo "name=$(node -p "require('./package.json').name")" >> "$GITHUB_OUTPUT"
- name: Upload *.tgz
if: ${{ steps.source-type.outputs.type }} == 'github'
uses: actions/upload-artifact@v3
with:
name: ${{ steps.build.outputs.name }}
path: ./*.tgz
- name: Extract tgz path
if: ${{ steps.source-type.outputs.type }} == 'github'
id: tgz
run: |
echo "path=$(ls ./*.tgz)" >> "$GITHUB_OUTPUT"
- name: Print tgz path
if: ${{ steps.source-type.outputs.type }} == 'github'
run: |
echo "Artifact: ${{ steps.tgz.outputs.path }}"