Skip to content

Commit fff64ce

Browse files
committed
Add: refactor gha workflow
1 parent 16f0ac3 commit fff64ce

File tree

1 file changed

+95
-19
lines changed

1 file changed

+95
-19
lines changed

.github/workflows/main.yml

Lines changed: 95 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,107 @@ on:
44
workflow_dispatch:
55

66
jobs:
7-
build:
7+
dev:
88
runs-on: ubuntu-latest
99
permissions:
1010
contents: write
1111
steps:
1212
- uses: actions/checkout@v3
13-
- name: Set up Docker
14-
uses: docker/setup-buildx-action@v1
15-
- name: Build and Test with Coverage
16-
run: |
17-
docker run --rm \
18-
-e PROPERTIES="BUILD_ID:${{ github.run_number }}" \
19-
-w "/app" \
20-
-v $PWD:/app \
21-
node:8 bash -c "npm i --no-save -q; npm run build; npm run coverage -- --reporter mocha-junit-reporter; chown -R $(id -u):$(id -g) ."
22-
- name: Setup .npmrc
23-
run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
13+
- name: Set up Node.js
14+
uses: actions/setup-node@v3
15+
with:
16+
node-version: '8'
17+
- name: Install dependencies
18+
run: npm i --no-save -q
19+
- name: Setup .npmrc for npmjs
20+
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
2421
env:
2522
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
26-
- name: Build and Publish to npmjs
23+
- name: Auto Increment Version, and Publish to npmjs
24+
run: |
25+
git config --global user.email "jaystack-ci@jaystack.com"
26+
git config --global user.name "jaystack-ci"
27+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
28+
npm version patch -m "Auto-increment version: %s" --force
29+
npm publish --tag dev
30+
env:
31+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
32+
- name: Git operations
33+
run: |
34+
git tag -f dev
35+
git push -f --tags
36+
git push
37+
stage:
38+
needs: dev
39+
runs-on: ubuntu-latest
40+
environment: stage
41+
permissions:
42+
contents: write
43+
steps:
44+
- uses: actions/checkout@v3
45+
with:
46+
ref: 'refs/tags/dev'
47+
48+
- name: Configure npm
49+
run: echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > .npmrc
50+
env:
51+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
52+
53+
- name: Extract package version
54+
id: package_version
55+
run: echo "::set-output name=VERSION::$(jq -r .version package.json)"
56+
shell: bash
57+
58+
- name: Configure Git
59+
run: |
60+
git config --global user.email "jaystack-ci@jaystack.com"
61+
git config --global user.name "jaystack-ci"
62+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
63+
64+
- name: Create and push git tag
65+
run: |
66+
git tag -f stage
67+
git push -f --tags
68+
69+
- name: Publish to npm
70+
run: npm dist-tag add functionly@${{ steps.package_version.outputs.VERSION }} stage
71+
env:
72+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
73+
74+
live:
75+
needs: stage
76+
runs-on: ubuntu-latest
77+
environment: live
78+
permissions:
79+
contents: write
80+
steps:
81+
- uses: actions/checkout@v3
82+
with:
83+
ref: 'refs/tags/stage'
84+
85+
- name: Configure npm
86+
run: echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > .npmrc
2787
env:
28-
NPM_VERSION: '1.0.0'
88+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
89+
90+
- name: Extract package version
91+
id: package_version
92+
run: echo "::set-output name=VERSION::$(jq -r .version package.json)"
93+
shell: bash
94+
95+
- name: Configure Git
96+
run: |
97+
git config --global user.email "jaystack-ci@jaystack.com"
98+
git config --global user.name "jaystack-ci"
99+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
100+
101+
- name: Create and push git tag
29102
run: |
30-
docker run --rm \
31-
-w "/app" \
32-
-v "$PWD:/app" \
33-
-v "${{ github.workspace }}/.npmrc:/root/.npmrc" \
34-
node:8 bash -c "npm i --no-save -q; npm run build; npm version ${NPM_VERSION} > version.txt; npm publish --tag dev; chown -R $(id -u):$(id -g) ."
103+
git tag -f latest
104+
git push -f --tags
105+
106+
- name: Publish to npm
107+
run: npm dist-tag add functionly@${{ steps.package_version.outputs.VERSION }} latest
108+
env:
109+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
110+

0 commit comments

Comments
 (0)