-
-
Notifications
You must be signed in to change notification settings - Fork 1
113 lines (98 loc) · 3.27 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
100
101
102
103
104
105
106
107
108
109
110
111
112
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:
artifact:
description: "Artifact name"
value: ${{ jobs.pack.outputs.artifact }}
path:
description: "Path to package"
value: ${{ jobs.pack.outputs.path }}
secrets:
RETE_QA_PUBLIC_PULL:
description: 'GitHub Personal access token'
required: true
jobs:
pack:
name: ${{ inputs.package }}
runs-on: ubuntu-latest
outputs:
artifact: ${{ steps.build.outputs.name }}
path: ${{ steps.result.outputs.path }}
steps:
- name: Detect source type
id: detect-source
run: |
regex_github='^[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: Check NPM Package Version
if: steps.detect-source.outputs.type == 'npm'
run: |
npm show ${{ inputs.package }} version || exit
- name: Extract repo and branch
if: steps.detect-source.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.detect-source.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.detect-source.outputs.type == 'github'
uses: actions/setup-node@v4
- name: Build
if: steps.detect-source.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.detect-source.outputs.type == 'github'
uses: actions/upload-artifact@v4
with:
name: ${{ steps.build.outputs.name }}
path: ./*.tgz
- name: Extract tgz path
if: steps.detect-source.outputs.type == 'github'
id: tgz
run: |
echo "path=$(ls ./*.tgz)" >> "$GITHUB_OUTPUT"
- name: Print tgz path
if: steps.detect-source.outputs.type == 'github'
run: |
echo "${{ steps.tgz.outputs.path }}"
- name: Output path
id: result
run: |
echo "path=${{ steps.detect-source.outputs.type == 'github' && steps.tgz.outputs.path || inputs.package }}" >> "$GITHUB_OUTPUT"