-
Notifications
You must be signed in to change notification settings - Fork 104
89 lines (75 loc) · 3.24 KB
/
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
name: Check and Publish NPM Version
on:
push:
branches:
- develop
- task/publish-on-merge
jobs:
check-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up bun
uses: oven-sh/setup-bun@v2
- name: Install and build
run: |
bun install
bun run build
- name: Get the latest release
id: get_latest_release
run: |
latest_release=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
echo "::set-output name=latest_release::${latest_release}"
- name: Get version from package.json
id: get_package_version
run: |
package_version=$(jq -r .version < ./package.json)
echo "::set-output name=package_version::${package_version}"
- name: Compare GitHub release version
id: compare_github_versions
run: |
if [ "${{ steps.get_latest_release.outputs.latest_release }}" == "${{ steps.get_package_version.outputs.package_version }}" ]; then
echo "GitHub release version matches package.json version."
echo "::set-output name=should_create_release::false"
else
echo "GitHub release version does not match package.json version."
echo "::set-output name=should_create_release::true"
fi
- name: Create GitHub release
if: steps.compare_github_versions.outputs.should_create_release == 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_package_version.outputs.package_version }}
release_name: Release ${{ steps.get_package_version.outputs.package_version }}
draft: false
prerelease: false
- name: Get latest NPM version
id: get_latest_npm_version
run: |
npm_version=$(npm show $(jq -r .name < ./package.json) version)
echo "::set-output name=npm_version::${npm_version}"
- name: Compare NPM version
id: compare_npm_versions
run: |
if [ "${{ steps.get_latest_npm_version.outputs.npm_version }}" == "${{ steps.get_package_version.outputs.package_version }}" ]; then
echo "NPM version matches package.json version."
echo "::set-output name=should_publish_npm::false"
else
echo "NPM version does not match package.json version."
echo "::set-output name=should_publish_npm::true"
fi
- name: Publish to NPM
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
if: steps.compare_npm_versions.outputs.should_publish_npm == 'true'
# run: bun run npm publish --//registry.npmjs.org/:_authToken=${NPM_TOKEN}
run: echo "This WOULD HAVE published to NPM"
- name: Success message
if: steps.compare_github_versions.outputs.should_create_release == 'false' && steps.compare_npm_versions.outputs.should_publish_npm == 'false' || success()
run: echo "NPM package and GitHub release are up to date or published successfully."
- name: Fail if publish failed
if: failure()
run: exit 1