Skip to content

Commit 41ecbeb

Browse files
authored
Merge pull request #52 from rsksmart/npm_OIDC
Modify to upload using OIDC
2 parents ee16214 + a95d988 commit 41ecbeb

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

.github/workflows/main.yml

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
1-
name: Publish library on NPM
1+
name: Deploy library on NPM
22

33
on:
44
release:
55
types: [published]
6-
6+
7+
# Declare default permissions as read only.
78
permissions: read-all
89

910
jobs:
1011
publish:
12+
permissions:
13+
id-token: write
14+
contents: read
15+
1116
runs-on: ubuntu-latest
1217

1318
steps:
1419
- name: Checkout
1520
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
16-
21+
1722
- name: "Check file existence"
1823
id: check_files
1924
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
2025
with:
2126
files: "package.json, README.md"
22-
27+
2328
- name: File exists
2429
if: steps.check_files.outputs.files_exists != 'true'
2530
# Only runs if all of the files exists
2631
run: exit 1
2732

2833
- name: Get package.json package name and match with repository name
2934
run: |
30-
echo PACKAGE_NAME=$(cat package.json | jq -r .name | sed 's/@//') >> $GITHUB_OUTPUT
35+
echo PACKAGE_NAME=$(cat package.json | jq -r .name | cut -f2 -d"\"" | cut -f2 -d"@") >> $GITHUB_OUTPUT
3136
echo PACKAGE_VERSION="refs/tags/v"$(cat package.json | jq -r .version) >> $GITHUB_OUTPUT
3237
echo PACKAGE_REPOSITORY=$(cat package.json | jq -r .repository.url | sed 's/\+https//') >> $GITHUB_OUTPUT
3338
id: get_package_info
@@ -50,35 +55,37 @@ jobs:
5055
if: github.ref != steps.get_package_info.outputs.PACKAGE_VERSION
5156
# Fail if package version not properly setted
5257
run: exit 1
53-
58+
5459
- name: Check if package repository matches with repository
5560
if: github.repositoryUrl != steps.get_package_info.outputs.PACKAGE_REPOSITORY
5661
# Fail if package repository doesn't match with repository
5762
run: exit 1
5863

5964
- name: Setup Node.js
60-
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 #v4.4.0
65+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af #v4.1.0
6166
with:
6267
node-version: 20
6368
registry-url: https://registry.npmjs.org
6469

65-
- name: Install pnpm
66-
run: npm install -g pnpm
70+
- name: Clean install dependencies
71+
run: |
72+
rm -rf dist
73+
npm ci
6774
68-
- name: Install dependencies
69-
run: pnpm install
75+
- name: Update npm
76+
run: npm install -g npm@latest
7077

7178
- name: Build
72-
run: pnpm build
79+
run: npm run build
7380

7481
- name: Pre upload validation
7582
id: pack
7683
run: |
77-
npm pack --dry-run > output 2>&1
78-
PRE_UPLOAD_HASH=$(grep 'shasum' output | awk '{print $NF}')
84+
rm -f *.tgz
85+
PRE_UPLOAD_HASH=$(npm pack --dry-run 2>&1 | grep 'shasum:' | awk '{print $NF}')
7986
echo "PRE_UPLOAD_HASH=$PRE_UPLOAD_HASH" >> $GITHUB_OUTPUT
8087
echo "PRE_UPLOAD_HASH: $PRE_UPLOAD_HASH"
81-
88+
8289
- name: Check if version is already published
8390
run: |
8491
PACKAGE_NAME=$(cat package.json | jq -r .name)
@@ -92,11 +99,8 @@ jobs:
9299
echo "Version $PACKAGE_VERSION of $PACKAGE_NAME is not published. Proceeding with publishing..."
93100
94101
- name: Upload package
95-
run: npm publish --access public
96-
env:
97-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
98-
99-
102+
run: npm publish
103+
100104
- name: Post upload validation
101105
id: unpack
102106
run: |
@@ -113,7 +117,7 @@ jobs:
113117
POST_UPLOAD_HASH=$(npm view $FULL_PACKAGE_NAME dist.shasum)
114118
echo "POST_UPLOAD_HASH=$POST_UPLOAD_HASH" >> $GITHUB_OUTPUT
115119
echo "POST_UPLOAD_HASH: $POST_UPLOAD_HASH"
116-
120+
117121
- name: Pre and Post Upload validation
118122
run: |
119123
echo "Comparing hashes..."
@@ -124,4 +128,5 @@ jobs:
124128
echo "Hash mismatch detected!"
125129
exit 1
126130
fi
127-
echo "Hashes match successfully!"
131+
echo "Hashes match successfully!"
132+

0 commit comments

Comments
 (0)