-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from TroyAlford/task/publish-on-merge
GH Actions publish-on-merge
- Loading branch information
Showing
7 changed files
with
111 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
name: Check and Publish NPM Version | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
|
||
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} | ||
|
||
- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
**/coverage | ||
**/dist | ||
**/node_modules | ||
**/npm-debug.log | ||
**/package-lock.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
**/.circleci | ||
**/.eslintrc | ||
**/.gitignore | ||
**/.vscode | ||
**/jest | ||
**/jest.config.js | ||
**/node_modules | ||
**/test-coverage | ||
**/webpack.*.js | ||
**/yarn-error.log | ||
|
||
**/demo.* | ||
**/*.html | ||
**/*.test.js | ||
**/*.test.tsx | ||
**/demo | ||
**/*.test.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters