Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/scripts/npm-publisher-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Asks npm whether this workflow is the trusted publisher of each public package: `npm-publisher-check.sh <folder>...`.
set -euo pipefail

id_token() {
curl -fsS -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=npm:registry.npmjs.org" | jq -r .value
}

bad=0
for dir in "$@"; do
[ -f "$dir/package.json" ] || continue
[ "$(jq -r '.private // false' "$dir/package.json")" = "true" ] && continue
name=$(jq -r .name "$dir/package.json")
url="https://registry.npmjs.org/-/npm/v1/oidc/token/exchange/package/$(jq -rn --arg n "$name" '$n|@uri')"
status=$(curl -sS -o /dev/null -w '%{http_code}' -X POST -H "Authorization: Bearer $(id_token)" "$url")
if [ "$status" = "201" ] || [ "$status" = "200" ]; then
echo "PASS $name: npm takes this workflow as its publisher"
else
echo "FAIL $name: npm answered $status: set the trusted publisher of $name to $GITHUB_REPOSITORY and $(basename "${GITHUB_WORKFLOW_REF%@*}")"
echo "::error title=npm publisher of $name::npm answered $status. No tag was made."
bad=1
fi
done
exit "$bad"
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ name: Release
on:
push:
branches: [master]
workflow_dispatch: # runs the checks again; an unchanged extension is not released

concurrency:
group: release
Expand Down Expand Up @@ -68,6 +69,10 @@ jobs:
env:
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: printf '%s' "$GHCR_TOKEN" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
# Before any tag: a publish that npm refuses would leave a tag and images with no record.
- name: npm takes this workflow as the publisher of each public package
if: steps.hold.outputs.any == 'true'
run: .github/scripts/npm-publisher-check.sh extensions/*/
- if: steps.hold.outputs.any == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down