Repository navigation
ci: publish definitions after each Framework release with trusted publishing #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
czubocha
wants to merge
5
commits into
master
Choose a base branch
from
branch/pensive-edison-g2r9s1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
75b8c7e
ci: publish definitions after each Framework release with trusted pub…
claude f23925d
fix: type schema properties without constraints as unknown
claude c931990
chore: drop unused ajv and delay resolving new npm releases
claude daed264
ci: add a dry-run mode to the release workflow
claude e33b998
ci: compare definitions with an existing tag before publishing
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| version: 2 | ||
| updates: | ||
| # The cooldown leaves new releases a few days to be reviewed upstream (and | ||
| # pulled if compromised) before a pull request proposes them. | ||
| - package-ecosystem: 'npm' | ||
| directory: '/' | ||
| schedule: | ||
| interval: 'weekly' | ||
| cooldown: | ||
| default-days: 5 | ||
| semver-major-days: 30 | ||
| semver-minor-days: 7 | ||
| semver-patch-days: 3 | ||
| groups: | ||
| dev-dependencies: | ||
| dependency-type: 'development' | ||
| update-types: ['minor', 'patch'] | ||
|
|
||
| - package-ecosystem: 'github-actions' | ||
| directory: '/' | ||
| schedule: | ||
| interval: 'weekly' | ||
| cooldown: | ||
| default-days: 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,32 @@ | ||
| name: Tests | ||
| on: push | ||
| on: | ||
| push: | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| tests: | ||
| name: Run serverless/typescript tests | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v2 | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
|
|
||
| - name: Install Node.js and npm | ||
| uses: actions/setup-node@v1 | ||
| uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 | ||
| with: | ||
| node-version: 20.x | ||
| registry-url: https://registry.npmjs.org | ||
| node-version: 24.x | ||
|
|
||
| - name: Install dependencies | ||
| run: npm i | ||
| run: npm ci | ||
|
|
||
| - name: Run lint tests | ||
| run: npm run test:lint | ||
|
|
||
| - name: Run type tests | ||
| run: npm run test:type | ||
|
|
||
| - name: Test definitions against a sample service | ||
| run: npm run test:definitions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,56 +1,233 @@ | ||
| name: Update and Release Serverless Definitions | ||
| on: | ||
| # Daily check: releases only when npm has a Framework version that | ||
| # @serverless/typescript has not published yet. | ||
| schedule: | ||
| - cron: '37 5 * * *' | ||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: Framework version to generate definitions for (defaults to the latest on npm) | ||
| required: false | ||
| allow-removed-types: | ||
| description: Publish even if the new definitions no longer export a type the previous ones did | ||
| type: boolean | ||
| default: false | ||
| dry-run: | ||
| description: Generate and test the definitions from any branch without committing or publishing | ||
| type: boolean | ||
| default: false | ||
| repository_dispatch: | ||
| types: [serverless-released] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: update-and-release-${{ github.event.inputs['dry-run'] == 'true' && github.ref || 'release' }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| generateTSDefinitions: | ||
| name: Generate serverless/serverless typescript definitions | ||
| resolveVersion: | ||
| name: Resolve Framework version | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| version: ${{ steps.resolve.outputs.version }} | ||
| release: ${{ steps.resolve.outputs.release }} | ||
| steps: | ||
| - name: Resolve version and check npm | ||
| id: resolve | ||
| env: | ||
| INPUT_VERSION: ${{ github.event.inputs.version || github.event.client_payload.version }} | ||
| DRY_RUN: ${{ github.event.inputs['dry-run'] == 'true' }} | ||
| run: | | ||
| version="${INPUT_VERSION:-$(npm view serverless version)}" | ||
| version="${version#v}" | ||
| if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo "::error::Invalid Framework version: $version" | ||
| exit 1 | ||
| fi | ||
| echo "version=$version" >> "$GITHUB_OUTPUT" | ||
|
|
||
| if [ "$DRY_RUN" = "true" ]; then | ||
| echo "Dry run for $version: nothing will be committed or published" | ||
| echo "release=true" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| if npm view "@serverless/typescript@$version" version 2>/dev/null | grep -q .; then | ||
| echo "@serverless/typescript@$version is already published" | ||
| echo "release=false" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Publishing an older version would move the latest dist-tag back. | ||
| latest="$(npm view @serverless/typescript version)" | ||
| if [ "$(printf '%s\n%s\n' "$latest" "$version" | sort -V | tail -1)" != "$version" ]; then | ||
| echo "::error::$version is older than the published latest, $latest" | ||
| exit 1 | ||
| fi | ||
| echo "release=true" >> "$GITHUB_OUTPUT" | ||
|
|
||
| # Runs the Framework CLI, which is installed at run time and not covered by | ||
| # package-lock.json. This job holds no write permissions and cannot publish; | ||
| # it hands only index.d.ts to the next jobs. | ||
| generate: | ||
| name: Generate definitions | ||
| needs: resolveVersion | ||
| if: >- | ||
| needs.resolveVersion.outputs.release == 'true' && | ||
| (github.ref == 'refs/heads/master' || github.event.inputs['dry-run'] == 'true') | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| VERSION: ${{ needs.resolveVersion.outputs.version }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v2 | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Install Node.js and npm | ||
| uses: actions/setup-node@v1 | ||
| uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 | ||
| with: | ||
| node-version: 20.x | ||
| registry-url: https://registry.npmjs.org | ||
| node-version: 24.x | ||
| check-latest: true | ||
| package-manager-cache: false | ||
|
|
||
| - name: Install dependencies | ||
| run: npm i | ||
| run: npm ci --ignore-scripts | ||
|
|
||
| - name: Build plugin | ||
| run: npm run build | ||
|
|
||
| - name: Set Serverless latest version | ||
| id: serverless-version | ||
| - name: Install the Serverless CLI and verify its provenance | ||
| run: | | ||
| version=$(npm list serverless | grep serverless@ | sed 's/.*serverless@/v/g' | tr -d '[[:space:]]') | ||
| echo "version=$version" >> $GITHUB_ENV | ||
| mkdir -p "$RUNNER_TEMP/installer" | ||
| cd "$RUNNER_TEMP/installer" | ||
| npm init -y >/dev/null | ||
| npm install --ignore-scripts --no-audit --no-fund "serverless@$VERSION" | ||
| npm audit signatures --json --include-attestations > "$RUNNER_TEMP/signatures.json" | ||
| node "$GITHUB_WORKSPACE/scripts/verify-installer-provenance.js" "$RUNNER_TEMP/signatures.json" "$VERSION" | ||
|
|
||
| - name: Generate TypeScript Definitions | ||
| run: npx sls schema | ||
| - name: Generate TypeScript definitions | ||
| env: | ||
| SERVERLESS_ACCESS_KEY: ${{secrets.SERVERLESS_ACCESS_KEY}} | ||
| SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }} | ||
| run: | | ||
| # The serverless npm package installs the Framework release that | ||
| # frameworkVersion names, so the definitions match $VERSION. | ||
| echo "frameworkVersion: '$VERSION'" >> serverless.yml | ||
| "$RUNNER_TEMP/installer/node_modules/.bin/serverless" --version 2>&1 | tee "$RUNNER_TEMP/version.txt" | ||
| grep -q "Framework $VERSION\b" "$RUNNER_TEMP/version.txt" | ||
| "$RUNNER_TEMP/installer/node_modules/.bin/serverless" schema | ||
| git diff --stat | ||
|
|
||
| - name: Update package.json version | ||
| run: npm version ${{ env.version }} --git-tag-version=false | ||
| - name: Upload definitions | ||
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | ||
| with: | ||
| name: definitions | ||
| path: index.d.ts | ||
| if-no-files-found: error | ||
| retention-days: 7 | ||
|
|
||
| - name: Commit changes | ||
| uses: EndBug/add-and-commit@v5 | ||
| # Tests the generated definitions from a clean checkout, with only locked | ||
| # dependencies and no install scripts. Read-only, so it also serves dry runs. | ||
| verify: | ||
| name: Test definitions | ||
| needs: [resolveVersion, generate] | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| VERSION: ${{ needs.resolveVersion.outputs.version }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| author_name: Eslam λ Hefnawy | ||
| author_email: eslam@serverless.com | ||
| branch: master | ||
| message: Add Serverless definitions for ${{ env.version }} | ||
| add: index.d.ts package.json | ||
| tag: ${{ env.version }} --force | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| persist-credentials: false | ||
|
|
||
| - name: Publish | ||
| uses: JS-DevTools/npm-publish@v1 | ||
| - name: Install Node.js and npm | ||
| uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 | ||
| with: | ||
| token: ${{ secrets.NPM_TOKEN }} | ||
| node-version: 24.x | ||
| check-latest: true | ||
| package-manager-cache: false | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci --ignore-scripts | ||
|
|
||
| - name: Keep previous definitions | ||
| run: cp index.d.ts "$RUNNER_TEMP/previous.d.ts" | ||
|
|
||
| - name: Download definitions | ||
| uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 | ||
| with: | ||
| name: definitions | ||
|
|
||
| - name: Test definitions | ||
| run: | | ||
| git diff --stat | ||
| npm run test:lint | ||
| npm run test:type | ||
| npm run test:definitions | ||
|
|
||
| - name: Check that no exported type was removed | ||
| if: github.event.inputs['allow-removed-types'] != 'true' | ||
| run: node scripts/check-exported-types.js "$RUNNER_TEMP/previous.d.ts" index.d.ts | ||
|
|
||
| - name: Show the package that would be published | ||
| run: | | ||
| npm version "$VERSION" --git-tag-version=false --allow-same-version | ||
| npm pack --dry-run | ||
|
|
||
| # The only job that can push or publish. It never runs for a dry run or off | ||
| # master, and it runs no dependencies: npm version and npm publish need none. | ||
| release: | ||
| name: Publish definitions | ||
| needs: [resolveVersion, verify] | ||
| if: github.ref == 'refs/heads/master' && github.event.inputs['dry-run'] != 'true' | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write # push the definitions commit and tag | ||
| id-token: write # npm trusted publishing | ||
| env: | ||
| VERSION: ${{ needs.resolveVersion.outputs.version }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
|
|
||
| - name: Install Node.js and npm | ||
| uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 | ||
| with: | ||
| node-version: 24.x | ||
| check-latest: true | ||
| package-manager-cache: false | ||
| registry-url: https://registry.npmjs.org | ||
|
|
||
| - name: Download definitions | ||
| uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 | ||
| with: | ||
| name: definitions | ||
|
|
||
| - name: Commit and tag definitions | ||
| run: | | ||
| npm version "$VERSION" --git-tag-version=false --allow-same-version | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| if git ls-remote --exit-code --tags origin "refs/tags/v$VERSION" >/dev/null; then | ||
| # An earlier run tagged this version but did not publish it: publish | ||
| # only if the definitions still match the tagged ones. | ||
| git fetch --no-tags origin "refs/tags/v$VERSION:refs/tags/v$VERSION" | ||
| if ! git show "refs/tags/v$VERSION:index.d.ts" | cmp -s - index.d.ts; then | ||
| echo "::error::Generated definitions differ from tag v$VERSION" | ||
| exit 1 | ||
| fi | ||
| echo "Tag v$VERSION exists, publishing without a new commit" | ||
| exit 0 | ||
| fi | ||
|
czubocha marked this conversation as resolved.
Resolved
|
||
| git add index.d.ts package.json package-lock.json | ||
| git commit -m "chore(release): add Serverless definitions for v$VERSION" | ||
| git tag "v$VERSION" | ||
| git push --atomic origin HEAD:master "v$VERSION" | ||
|
|
||
| - name: Publish to npm | ||
| run: | | ||
| npm pack --dry-run | ||
| npm publish | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| dist | ||
| node_modules | ||
| package-lock.json | ||
| .serverless |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,6 @@ dist | |
| node_modules | ||
| src | ||
| serverless.yml | ||
| test | ||
| .serverless | ||
| scripts | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| package-lock=false | ||
| # Versions published less than 3 days ago do not resolve when the lockfile changes. | ||
| min-release-age=3 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: serverless/typescript
Length of output: 25450
Script executed:
Repository: serverless/typescript
Length of output: 6182
Check package contents against the existing tag.
If a retry follows a change to
package.jsonor another packed file, the definitions can match whilenpm publishuses different package contents from the release tag. Compare the packed contents of the tag and the release checkout before publishing.