Skip to content

Commit a6241b0

Browse files
authored
Merge pull request #83 from aep-dev/mdk/publish-workflow-try3
Try 3 at publish workflow
2 parents 1d782e9 + 038a490 commit a6241b0

File tree

6 files changed

+69
-122
lines changed

6 files changed

+69
-122
lines changed

.github/workflows/auto-tag.yaml

Lines changed: 0 additions & 59 deletions
This file was deleted.

.github/workflows/node.js.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,11 @@ jobs:
2525
- run: npm run build --if-present
2626
- run: npm test
2727
- run: npm run lint
28+
29+
status-check:
30+
name: Node.js CI
31+
runs-on: ubuntu-latest
32+
needs: build
33+
if: always()
34+
steps:
35+
- run: exit 0

.github/workflows/release.yaml

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,40 @@ name: Publish to npm
22

33
on:
44
push:
5-
tags:
6-
- 'v*'
5+
branches:
6+
- main
7+
paths:
8+
- 'package.json'
79

810
jobs:
9-
publish:
11+
publish-release:
1012
runs-on: ubuntu-latest
1113

1214
permissions:
1315
contents: write
1416

1517
steps:
1618
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0 # Fetch all history for tag checking
1721

18-
- name: Verify tagged commit is in main branch history
22+
- name: Get version from package.json
23+
id: package-version
1924
run: |
20-
git fetch origin main
21-
if ! git merge-base --is-ancestor $GITHUB_SHA origin/main; then
22-
echo "Tag is not based on main. Aborting release."
23-
exit 1
25+
VERSION=$(node -p "require('./package.json').version")
26+
echo "version=$VERSION" >> $GITHUB_OUTPUT
27+
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
28+
29+
- name: Check if version changed
30+
run: |
31+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
32+
CURRENT_TAG="v${{ steps.package-version.outputs.version }}"
33+
34+
if [ "$LATEST_TAG" = "$CURRENT_TAG" ]; then
35+
echo "Version $CURRENT_TAG has not changed from latest tag. Skipping release."
36+
exit 0
37+
else
38+
echo "New version detected: $CURRENT_TAG (previous: $LATEST_TAG)"
2439
fi
2540
2641
- uses: actions/setup-node@v4
@@ -29,8 +44,22 @@ jobs:
2944
registry-url: https://registry.npmjs.org
3045

3146
- run: npm ci
47+
3248
- run: npm test
3349

50+
- name: Create and push tag
51+
run: |
52+
git config user.name "github-actions[bot]"
53+
git config user.email "github-actions[bot]@users.noreply.github.com"
54+
TAG="${{ steps.package-version.outputs.tag }}"
55+
# Try to create the tag; if it already exists locally, continue.
56+
git tag -a "$TAG" -m "Release $TAG" || echo "Tag $TAG already exists locally, continuing."
57+
# Try to push the tag. If the push fails, bail out.
58+
if ! git push origin "$TAG"; then
59+
echo "Failed to push tag $TAG to remote (may already exist)."
60+
exit 1
61+
fi
62+
3463
- name: Publish to npm
3564
run: npm publish
3665
env:

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ npm install
2222
npm test
2323
```
2424

25+
## Development Workflow
26+
27+
1. Use feature branches for development.
28+
2. PRs for new features should target the main branch.
29+
2530
### The example test
2631

2732
The input file for the `test/example/example.test.js` is taken from the

RELEASING.md

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,6 @@ about**, with minimal tooling and clear sources of truth.
88

99
---
1010

11-
## Overview
12-
13-
- Use `npm run release:{patch,minor,major}` to create a release branch.
14-
- Push that branch and open a PR to main.
15-
- Merging that branch triggers workflows that create a tag and publish the
16-
release.
17-
- The auto-tag workflow creates the new tag.
18-
- The release workflow sees the new tag and publishes the npm and GitHub
19-
releases.
20-
21-
No release bots, changelog generators, or additional CLIs are required.
22-
23-
---
24-
2511
## Versioning
2612

2713
This project follows **Semantic Versioning (SemVer)**:
@@ -31,9 +17,6 @@ This project follows **Semantic Versioning (SemVer)**:
3117
- **Major** (`x.0.0`) — breaking changes (rule behavior changes, removals,
3218
stricter defaults)
3319

34-
Versions can be updated manually in package.json or using npm’s built-in
35-
tooling.
36-
3720
---
3821

3922
## Creating a Release
@@ -58,43 +41,35 @@ This script will:
5841

5942
Then create a Pull Request to merge the release branch into main.
6043

61-
Once the PR is merged, **the tag is created automatically**.
44+
Once the PR is merged, the `release` workflow will run since the PR makes
45+
changes to package.json. This workflow will run the tests (again), and if the
46+
tests pass will then attempt to create a tag for the new version. If that
47+
succeeds, it then creates a release in both npm and GitHub.
6248

63-
The `auto-tag` workflow monitors package.json changes on main and automatically
64-
creates the corresponding git tag if it doesn't exist.
49+
The release branch can be deleted after the PR is merged and the releases are
50+
published.
6551

66-
When the tag is created on main, this triggers the `release` workflow, which
67-
will create the release in npm and in GitHub.
52+
No release bots, changelog generators, or additional CLIs are required.
6853

6954
---
7055

7156
## Automation (GitHub Actions)
7257

73-
### Automatic Tagging
74-
75-
The `auto-tag` workflow monitors package.json changes on the main branch. When
76-
a version change is detected, it automatically:
58+
### Release Workflow
7759

78-
1. Reads the version from package.json
79-
2. Checks if a tag for that version already exists
80-
3. Creates and pushes the tag if it doesn't exist
60+
The `release` workflow is triggered by a push to 'main' (e.g. a PR merge) that
61+
modifies "package json'. When triggered, it
8162

82-
This eliminates the manual tagging step after PR merge.
83-
84-
### Publishing and Releases
85-
86-
The `release` workflow listens for pushed tags matching `v*` on the main
87-
branch.
88-
89-
On tag push, it will:
90-
91-
1. Check out the repository
92-
2. Install dependencies
93-
3. Run tests
63+
1. Check if a tag already exists for this version. If so, the workflow
64+
terminates.
65+
2. Install dependencies and run the tests. These should never fail since PRs
66+
targeting main must pass CI, but this is an extra precaution.
67+
3. Create and push a git tag matching the version in package.json
9468
4. Publish the package to npm
95-
5. Create a GitHub Release for the tag
69+
5. Create a GitHub Release with auto-generated notes
9670

97-
The GitHub Release is only created if npm publishing succeeds.
71+
This single workflow handles the entire release process and ensures the npm and
72+
GitHub releases are in sync and use the version from package.json
9873

9974
---
10075

@@ -116,18 +91,6 @@ Publishing requires:
11691
- An npm automation token stored as a GitHub secret named `NPM_TOKEN`
11792
- `publishConfig.access` set appropriately in `package.json`
11893

119-
Example:
120-
121-
```json
122-
{
123-
"publishConfig": {
124-
"access": "public"
125-
}
126-
}
127-
```
128-
129-
---
130-
13194
## Optional: Changelog
13295

13396
A manual `CHANGELOG.md` may be maintained if desired.

scripts/prepare-release.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ npm test
6464
# Run linter
6565
echo "Running linter..."
6666
npm run lint
67+
6768
# Bump version
6869
echo "Bumping version ($VERSION_TYPE)..."
6970
npm version "$VERSION_TYPE" --no-git-tag-version

0 commit comments

Comments
 (0)