-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (104 loc) · 4.04 KB
/
_deploy.yml
File metadata and controls
121 lines (104 loc) · 4.04 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
name: Deploy package
on:
workflow_call:
inputs:
package-name:
required: true
type: string
secrets:
NPM_TOKEN:
required: true
jobs:
deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./packages/${{ inputs.package-name }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- name: Summary Head
run: |
echo "# Deployment Summary" >> $GITHUB_STEP_SUMMARY
echo "Date: $(date) " >> $GITHUB_STEP_SUMMARY
echo "Run ID: ${{ github.run_id }} " >> $GITHUB_STEP_SUMMARY
echo "Run Number: ${{ github.run_number }} " >> $GITHUB_STEP_SUMMARY
echo "Run Attempt: ${{ github.run_attempt }} " >> $GITHUB_STEP_SUMMARY
echo "Node Version: $(node --version) - NPM Version: $(npm --version) " >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "Package Name: **${{ inputs.package-name }}** " >> $GITHUB_STEP_SUMMARY
- name: Read package.json
id: package-json
run: |
echo "PACKAGE_JSON<<GH-EOF" >> $GITHUB_ENV
cat ./package.json >> $GITHUB_ENV
echo "GH-EOF" >> $GITHUB_ENV
- name: "Read package version"
run: |
version=${{ fromJson(env.PACKAGE_JSON).version }}
escaped_version=$(printf '%s\n' "$version" | sed -e 's/[]\/$*.^[]/\\&/g')
echo "VERSION=$version" >> $GITHUB_ENV
echo "ESCAPED_VERISON=$escaped_version" >> $GITHUB_ENV
echo "Package Version: **$version** " >> $GITHUB_STEP_SUMMARY
- name: Install
run: npm ci
- name: Build
run: npm run compile
- name: Lint
run: npm run lint
- name: Test
run: npm run test
- name: Publish
run: |
npm publish
echo "" >> $GITHUB_STEP_SUMMARY
echo "Successfully published to the [NPM registry](https://www.npmjs.com/package/@sourcelib/${{inputs.package-name}}/v/$VERSION)" >> $GITHUB_STEP_SUMMARY
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Get Changelog
id: changelog
run: |
changelog=`sed -n "/^## \[$ESCAPED_VERSION]/,/^## /p" CHANGELOG.md | sed '$ d' | sed '1,1d'`
changelog1="${changelog//'%'/'%25'}"
changelog1="${changelog1//$'\n'/'%0A'}"
changelog1="${changelog1//$'\r'/'%0D'}"
changelog2="${changelog//$'\n'/'\\n'}"
changelog2="${changelog2//$'\r'/'\\r'}"
changelog2="${changelog2//$'('/'\('}"
changelog2="${changelog2//$')'/'\)'}"
changelog2="${changelog2//$'`'/'\`'}"
changelog2="${changelog2//$'"'/'\"'}"
changelog2="${changelog2//"'"/"'\''"}"
echo "CL_ESCAPED=$changelog" >> $GITHUB_ENV
echo "CL_UNESCAPED=$changelog1" >> $GITHUB_ENV
echo "CL_DOUBLEESCAPED=$changelog2" >> $GITHUB_ENV
- name: Github Release
id: release
uses: softprops/action-gh-release@v1
with:
body: "${{env.CL_UNESCAPED}}"
tag_name: "${{inputs.package-name}}-${{env.VERSION}}"
- name: Prepare Discord Message
id: discord-msg
working-directory: ./
run: |
awk '{
gsub("#VERSION#","${{env.VERSION}}",$0);
gsub("#PACKAGE#","${{inputs.package-name}}",$0);
gsub("#DESCRIPTION#","${{env.CL_DOUBLEESCAPED}}",$0);
print $0;
}' ./.github/workflows/deploy_discord_message.json > ./.github/workflows/deploy_discord_message2.json
- name: Send Discord Message
uses: tsickert/discord-webhook@v4.0.0
# working-directory: ./
with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
raw-data: "./.github/workflows/deploy_discord_message2.json"
- name: Summary Footer
run: |
echo "Created GitHub [Release](https://github.com/source-lib/sourcelib/releases/tag/${{inputs.package-name}}-$VERSION)" >> $GITHUB_STEP_SUMMARY
echo "Discord Message sent successfully" >> $GITHUB_STEP_SUMMARY