Skip to content

Commit a257023

Browse files
committed
Pipeline updated
1 parent b220fc4 commit a257023

File tree

1 file changed

+60
-115
lines changed

1 file changed

+60
-115
lines changed

.github/workflows/publish.yml

Lines changed: 60 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,93 @@
1-
name: Publish npm Package
1+
name: Publish npm package
22

33
on:
44
push:
55
tags:
66
- 'v*'
77

8-
env:
9-
NODE_VERSION: '18'
10-
118
jobs:
12-
version:
9+
publish:
1310
runs-on: ubuntu-latest
1411

1512
steps:
1613
- name: Checkout code
1714
uses: actions/checkout@v4
1815
with:
1916
fetch-depth: 0
20-
token: ${{ secrets.PAT }}
2117

22-
- name: Set up Node.js
18+
- name: Setup Node.js
2319
uses: actions/setup-node@v4
2420
with:
25-
node-version: ${{ env.NODE_VERSION }}
21+
node-version: '18'
22+
registry-url: 'https://registry.npmjs.org'
2623

27-
- name: Extract version from tag
28-
id: version
24+
- name: Get tag info
25+
id: tag
2926
run: |
30-
TAG_VERSION=${GITHUB_REF#refs/tags/v}
31-
echo "version=$TAG_VERSION" >> $GITHUB_OUTPUT
27+
echo "Extracting tag name from GITHUB_REF..."
28+
TAG_NAME=${GITHUB_REF#refs/tags/}
29+
echo "TAG_NAME=$TAG_NAME"
30+
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
31+
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_OUTPUT
3232
33-
- name: Check if version needs to be updated
34-
id: check_version
33+
- name: Determine branch and version
34+
id: version
3535
run: |
36-
CURRENT_VERSION=$(node -p "require('./package.json').version")
37-
TAG_VERSION=${{ steps.version.outputs.version }}
38-
if [ "$CURRENT_VERSION" == "$TAG_VERSION" ]; then
39-
echo "Version not changed. Skipping version bump."
40-
echo "skip_version_bump=true" >> $GITHUB_OUTPUT
36+
echo "Determining branch and version..."
37+
if [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
38+
echo "Tag was created from the develop branch."
39+
TIMESTAMP=$(date -u +"%Y%m%d%H%M%S")
40+
VERSION="${TAG_NAME}-dev${TIMESTAMP}"
41+
echo "VERSION=$VERSION"
42+
echo "VERSION=$VERSION" >> $GITHUB_ENV
43+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
44+
echo "CHANNEL=dev" >> $GITHUB_ENV
4145
else
42-
echo "Version needs to be updated."
43-
echo "skip_version_bump=false" >> $GITHUB_OUTPUT
46+
echo "Tag was created from the master branch."
47+
VERSION="${TAG_NAME}"
48+
echo "VERSION=$VERSION"
49+
echo "VERSION=$VERSION" >> $GITHUB_ENV
50+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
51+
echo "CHANNEL=latest" >> $GITHUB_ENV
4452
fi
4553
46-
- name: Bump version in package.json
47-
if: steps.check_version.outputs.skip_version_bump == 'false'
48-
run: |
49-
npm install
50-
npm version ${{ steps.version.outputs.version }} --no-git-tag-version
51-
git config --global user.name "GitHub Actions"
52-
git config --global user.email "[email protected]"
53-
git fetch origin ${{ github.ref_name }}
54-
git pull origin ${{ github.ref_name }} --rebase
55-
git add package.json package-lock.json
56-
git commit -m "Bump version to ${{ steps.version.outputs.version }} [skip ci]"
57-
git push origin HEAD:${{ github.ref_name }}
58-
59-
- name: Rename tag for develop branch
60-
if: github.ref_name == 'develop'
54+
- name: Update package.json version
6155
run: |
62-
TIMESTAMP=$(date -u +"%Y%m%d%H%M%S")
63-
NEW_TAG="v${{ steps.version.outputs.version }}-dev$TIMESTAMP"
64-
echo "New tag: $NEW_TAG"
65-
git tag $NEW_TAG ${{ github.sha }}
66-
git push origin :refs/tags/${{ github.ref_name }}
67-
git push origin $NEW_TAG
68-
69-
- name: Upload package files
70-
uses: actions/upload-artifact@v4
71-
with:
72-
name: package-files
73-
path: |
74-
package.json
75-
package-lock.json
76-
77-
build:
78-
runs-on: ubuntu-latest
79-
needs: version
80-
81-
steps:
82-
- name: Download package files
83-
uses: actions/download-artifact@v4
84-
with:
85-
name: package-files
86-
path: .
87-
88-
- name: Checkout code
89-
uses: actions/checkout@v4
90-
91-
- name: Set up Node.js
92-
uses: actions/setup-node@v4
93-
with:
94-
node-version: ${{ env.NODE_VERSION }}
56+
echo "Updating package.json version to ${{ env.VERSION }}..."
57+
npm version ${{ env.VERSION }} --no-git-tag-version
58+
echo "Updated package.json:"
59+
cat package.json
9560
9661
- name: Install dependencies
97-
run: npm install
98-
99-
- name: Run build
100-
run: npm run build
101-
102-
- name: Upload build artifacts
103-
uses: actions/upload-artifact@v4
104-
with:
105-
name: build-output
106-
path: dist/
107-
108-
publish:
109-
runs-on: ubuntu-latest
110-
needs: [build]
111-
if: |
112-
github.ref_name == 'master' ||
113-
github.ref_name == 'develop'
114-
115-
steps:
116-
- name: Download package files
117-
uses: actions/download-artifact@v4
118-
with:
119-
name: package-files
120-
path: .
121-
122-
- name: Checkout code
123-
uses: actions/checkout@v4
124-
125-
- name: Set up Node.js
126-
uses: actions/setup-node@v4
127-
with:
128-
node-version: ${{ env.NODE_VERSION }}
129-
registry-url: 'https://registry.npmjs.org'
130-
131-
- name: Download build artifacts
132-
uses: actions/download-artifact@v4
133-
with:
134-
name: build-output
135-
path: dist/
62+
run: |
63+
echo "Installing dependencies..."
64+
npm install
65+
echo "Dependencies installed."
13666
137-
- name: Install dependencies
138-
run: npm install
67+
- name: Build package
68+
run: |
69+
echo "Building package..."
70+
npm run build
71+
echo "Build completed."
13972
14073
- name: Publish to npm
14174
run: |
142-
if [ "${{ github.ref_name }}" == "develop" ]; then
143-
npm publish --tag dev
144-
else
145-
npm publish
146-
fi
75+
echo "Publishing package to npm with tag ${{ env.CHANNEL }}..."
76+
npm publish --tag ${{ env.CHANNEL }}
77+
echo "Package published successfully."
14778
env:
14879
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
80+
81+
- name: Commit and push changes to develop
82+
if: github.ref == 'refs/heads/develop'
83+
run: |
84+
echo "Preparing to commit and push changes to develop..."
85+
git config --global user.name "GitHub Actions"
86+
git config --global user.email "[email protected]"
87+
echo "Staging package.json and package-lock.json..."
88+
git add package.json package-lock.json
89+
echo "Committing changes..."
90+
git commit -m "Update version to ${{ env.VERSION }} [skip ci]"
91+
echo "Pushing changes to develop..."
92+
git push origin develop
93+
echo "Changes pushed to develop."

0 commit comments

Comments
 (0)