-
Notifications
You must be signed in to change notification settings - Fork 8
135 lines (124 loc) · 4.07 KB
/
release-and-publish.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: Release and Publish
on:
workflow_dispatch:
inputs:
semver_type:
description: "What semver type is this release?"
type: choice
required: true
options:
- patch
- minor
prerelease:
description: "Pre Release"
type: boolean
required: false
jobs:
create-release:
if: github.event_name != 'workflow_dispatch' || github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
npm_package_version: ${{ steps.update_version.outputs.version_number }}
steps:
- uses: actions/checkout@v4
with:
ssh-key: ${{secrets.DEPLOY_TO_MAIN_KEY}}
- uses: actions/setup-node@v4
- run: npm ci
- run: npm run build
- run: npm run lint
- run: npm test
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_SIGNING_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
git_committer_name: github-actions[bot]
git_committer_email: 41898282+github-actions[bot]@users.noreply.github.com
- id: update_version
name: Update Package Version
run: |
echo foo > bar.txt
set -e
if [[ ${{ inputs.prerelease }} ]]; then
# save the value would be created, then remove all changes
new_version=$(npm version ${{ inputs.semver_type }} --no-commit-hooks --no-git-tag-version )
git reset --hard
else
new_version=$(npm version ${{ inputs.semver_type }} --sign-git-tag )
git push && git push --tags
fi
echo "Created version ${new_version}"
echo "version_number=$new_version" >> $GITHUB_OUTPUT
- id: pack_tar
run: |
npm run build
echo "tar_name=$(npm pack)" >> $GITHUB_OUTPUT
- uses: ncipollo/release-action@v1
with:
artifacts: "${{ steps.pack_tar.outputs.tar_name }}"
tag: "${{ steps.update_version.outputs.version_number }}"
generateReleaseNotes: true
prerelease: ${{ inputs.prerelease }}
publish-npm:
needs: create-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# setup .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm run compile
# Publish to npm
- run: |
if [[ ${{ inputs.prerelease }} == 'true' ]]; then
npm publish --access public --dry-run
else
npm publish --access public
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.PUBLISH_NPM_TOKEN }}
publish-gpr:
needs: create-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
registry-url: https://npm.pkg.github.com/
scope: '@emandm'
# Publish to GitHub Packages
- run: npm ci
- run: npm run compile
- name: Update Package Name
run: |
sed -i 's,"name": "ts-mock-imports","name": "@emandm/ts-mock-imports",' package.json
cat package.json
- run: echo registry=https://npm.pkg.github.com/emandm >> .npmrc
- run: |
if [[ ${{ inputs.prerelease }} == 'true' ]]; then
npm publish --dry-run
else
npm publish
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
external_test:
runs-on: ubuntu-latest
needs: [create-release, publish-npm]
if: ${{ !inputs.prerelease }}
steps:
- uses: actions/setup-node@v4
- uses: actions/checkout@v4
with:
repository: EmandM/import-test
- run: npm ci
- run: npm uninstall ts-mock-imports # Ensure no contamination from existing version
- run: npm install ts-mock-imports@${{ needs.create-release.outputs.npm_package_version }}
- run: npm test