-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (132 loc) · 4.67 KB
/
ci.yaml
File metadata and controls
132 lines (132 loc) · 4.67 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: CI
on:
workflow_dispatch: null
push:
tags:
- v*
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
arch:
- x64
node:
- 14.0.0
include:
- os: ubuntu-latest
platform: linux
publish: true
name: Build on node-v${{ matrix.node }}-${{ matrix.platform }}-${{ matrix.arch }}
outputs:
build: ${{ steps.meta.outputs.build }}
publish: ${{ steps.meta.outputs.publish }}
steps:
- uses: actions/checkout@v2
- id: meta
name: Build metadata
uses: actions/github-script@v5
env:
REPO_NAME: ${{ github.repository }}
MATRIX_OS: ${{ matrix.os }}
MATRIX_PLATFORM: ${{ matrix.platform }}
MATRIX_ARCH: ${{ matrix.arch }}
MATRIX_PUBLISH: ${{ matrix.publish }}
MATRIX_NODE: ${{ matrix.node }}
with:
script: |-
const env = process.env;
const result = {};
result.targetOs = env.MATRIX_OS;
result.targetNode = env.MATRIX_NODE;
result.targetName = "node-v" + env.MATRIX_NODE + "-" + env.MATRIX_PLATFORM + "-" + env.MATRIX_ARCH;
const pkg = require('./package.json');
const [pkgNameOwner, pkgName] = pkg.name.slice(1).split("/");
result.nodePkg = {};
result.nodePkg.owner = pkgNameOwner;
const pkgFullName = pkgNameOwner + "-" + pkgName + "-v" + pkg.version;
result.nodePkg.artifactName = pkgFullName + "-" + result.targetName + ".nodepkg";
result.nodePkg.fileName = result.nodePkg.artifactName + ".tgz";
if (env.MATRIX_PUBLISH)
core.setOutput('publish', result);
return result;
- uses: actions/setup-node@v2
- uses: bahmutov/npm-install@v1
- run: mkdir -p /tmp/artifact/nodepkg
- name: Test Node.js pkg
run: npm run test --if-present
- name: Pack Node.js pkg
run: |-
npm pack
mv *.tgz /tmp/artifact/nodepkg/${{ fromJson(steps.meta.outputs.result).nodePkg.fileName }}
- name: Upload Node.js pkg
uses: actions/upload-artifact@v2
with:
name: ${{ fromJson(steps.meta.outputs.result).nodePkg.artifactName }}
path: /tmp/artifact/nodepkg/*
if-no-files-found: error
retention-days: 7
publish-github-release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs:
- build
name: Publish release in GitHub
steps:
- name: Create
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: mkdir -p /tmp/artifact/nodepkg
- name: Download Node.js pkg
uses: actions/download-artifact@v2
with:
path: /tmp/artifact/nodepkg
- name: Attach Node.js pkg
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: /tmp/artifact/nodepkg/**/*.tgz
publish-github-nodepkg:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ${{ fromJson(needs.build.outputs.publish).targetOs }}
needs:
- build
name: Publish Node.js pkg in GitHub
steps:
- name: Download
uses: actions/download-artifact@v2
with:
name: ${{ fromJson(needs.build.outputs.publish).nodePkg.artifactName }}
- uses: actions/setup-node@v2
with:
scope: "@${{ fromJson(needs.build.outputs.publish).nodePkg.owner }}"
node-version: ${{ fromJson(needs.build.outputs.publish).targetNode }}
registry-url: https://npm.pkg.github.com
- name: Publish
run: npm publish ${{ fromJson(needs.build.outputs.publish).nodePkg.fileName }} --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-npm-nodepkg:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ${{ fromJson(needs.build.outputs.publish).targetOs }}
needs:
- build
name: Publish Node.js pkg in NPM
steps:
- name: Download
uses: actions/download-artifact@v2
with:
name: ${{ fromJson(needs.build.outputs.publish).nodePkg.artifactName }}
- uses: actions/setup-node@v2
with:
scope: "@${{ fromJson(needs.build.outputs.publish).nodePkg.owner }}"
node-version: ${{ fromJson(needs.build.outputs.publish).targetNode }}
registry-url: https://registry.npmjs.org
- name: Publish
run: npm publish ${{ fromJson(needs.build.outputs.publish).nodePkg.fileName }} --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}