Skip to content

Commit e9f1e2d

Browse files
committed
Secure the publication to npm/Docker
1 parent 4721b6f commit e9f1e2d

1 file changed

Lines changed: 28 additions & 20 deletions

File tree

.github/workflows/push.yml

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,10 @@ jobs:
4040
with:
4141
sonar-token: ${{ secrets.SONAR_TOKEN }}
4242
- name: "Build package"
43-
run: "npm run build"
44-
- name: "Store build output"
45-
uses: "actions/upload-artifact@v7"
46-
with:
47-
if-no-files-found: "error"
48-
name: "fauxauth-lib"
49-
path: "packages/fauxauth/lib"
43+
run: |
44+
npm run build
45+
npm --workspace fauxauth pack
46+
mv fauxauth-*.tgz package.tgz
5047
- name: "Set up Docker BuildX"
5148
uses: "docker/setup-buildx-action@v4"
5249
- name: "Build Docker container"
@@ -59,6 +56,18 @@ jobs:
5956
cache-to: type=gha,mode=max
6057
context: .
6158
push: false
59+
- name: "Store build output"
60+
uses: "actions/upload-artifact@v7"
61+
with:
62+
if-no-files-found: "error"
63+
name: "fauxauth-lib"
64+
path: "packages/fauxauth/lib"
65+
- name: "Store package output"
66+
uses: "actions/upload-artifact@v7"
67+
with:
68+
if-no-files-found: "error"
69+
name: "fauxauth-pkg"
70+
path: "package.tgz"
6271
e2e:
6372
needs:
6473
- "build"
@@ -81,6 +90,9 @@ jobs:
8190
- "e2e"
8291
if: startsWith(github.ref, 'refs/tags/v')
8392
runs-on: "ubuntu-latest"
93+
environment:
94+
name: "docker"
95+
url: "https://hub.docker.com/r/textbook/fauxauth"
8496
steps:
8597
- name: "Check out repository"
8698
uses: "actions/checkout@v6"
@@ -99,7 +111,7 @@ jobs:
99111
uses: "docker/login-action@v4"
100112
with:
101113
password: ${{ secrets.DOCKER_PASSWORD }}
102-
username: ${{ secrets.DOCKER_USERNAME }}
114+
username: ${{ vars.DOCKER_USERNAME }}
103115
- name: "Build and push container"
104116
uses: "docker/build-push-action@v7"
105117
with:
@@ -123,7 +135,7 @@ jobs:
123135
with:
124136
password: ${{ secrets.DOCKER_PASSWORD }}
125137
repository: "textbook/fauxauth"
126-
username: ${{ secrets.DOCKER_USERNAME }}
138+
username: ${{ vars.DOCKER_USERNAME }}
127139
deploy-github:
128140
needs:
129141
- "e2e"
@@ -158,28 +170,24 @@ jobs:
158170
needs:
159171
- "e2e"
160172
if: startsWith(github.ref, 'refs/tags/v')
173+
environment:
174+
name: "npm"
175+
url: "https://www.npmjs.com/package/fauxauth"
161176
runs-on: "ubuntu-latest"
162177
steps:
163-
- name: "Check out repository"
164-
uses: "actions/checkout@v6"
165178
- name: "Retrieve build output"
166179
uses: "actions/download-artifact@v8"
167180
with:
168-
name: "fauxauth-lib"
169-
path: "packages/fauxauth/lib"
170-
- name: "Include LICENSE and README"
171-
run: "cp LICENSE README.md packages/fauxauth/"
181+
name: "fauxauth-pkg"
172182
- name: "Set up Node environment"
173183
uses: "actions/setup-node@v6"
174184
id: "setup-node"
175185
with:
176-
node-version-file: ".nvmrc"
186+
node-version: "lts/*"
177187
- name: "Publish to NPM"
178-
env:
179-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
180188
run: |
181-
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > "$HOME/.npmrc"
182-
npm --workspace packages/fauxauth publish
189+
npm install --global npm@latest
190+
npm publish --provenance package.tgz
183191
smoke-test:
184192
needs:
185193
- "deploy-docker"

0 commit comments

Comments
 (0)