-
Notifications
You must be signed in to change notification settings - Fork 16
91 lines (75 loc) · 2.61 KB
/
Copy pathmain.yml
File metadata and controls
91 lines (75 loc) · 2.61 KB
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
90
name: CI/CD Pipeline
on:
pull_request: # Triggers on PRs to master
branches:
- master
push: # Triggers when a PR is merged into master
branches:
- master
jobs:
ci:
name: Run Checks
runs-on: ubuntu-latest
outputs:
should_publish: ${{ steps.version_check.outputs.should_publish }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install Dependencies
run: npm ci
- name: Run Linter
run: npm run lint
- name: Run Prettier Check
run: npm run format:check
- name: Run Tests with Coverage
run: npm run test:coverage
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: joanllenas/ts.data.json
- name: Build Project
run: npm run build
- name: Check if Version Exists on NPM
id: version_check
run: |
CURRENT_VERSION=$(npm view ts.data.json version || echo "0.0.0")
NEW_VERSION=$(node -p "require('./package.json').version")
if [ "$CURRENT_VERSION" == "$NEW_VERSION" ]; then
echo "Version $NEW_VERSION already exists on NPM. Skipping publish."
echo "::warning::Version $NEW_VERSION already exists on NPM. The package won't be published unless you update the version in package.json"
echo "should_publish=false" >> "$GITHUB_OUTPUT"
else
echo "Version $NEW_VERSION is new. Will publish."
echo "should_publish=true" >> "$GITHUB_OUTPUT"
fi
release:
name: Publish to NPM
needs: ci # Only runs if CI passes
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # OIDC token for npm Trusted Publishing (no NPM_TOKEN needed)
# Only runs on master push and if version doesn't exist
if: |
github.event_name == 'push' &&
github.ref == 'refs/heads/master' &&
needs.ci.outputs.should_publish == 'true'
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
registry-url: 'https://registry.npmjs.org'
# Trusted Publishing (OIDC) requires npm >= 11.5.1
- name: Upgrade npm
run: npm install -g npm@latest
- name: Install Dependencies
run: npm ci
- name: Build Project
run: npm run build
# Authenticates via the OIDC id-token; provenance is generated automatically.
- name: Publish to NPM
run: npm publish