Last active
August 19, 2025 23:19
-
-
Save ammuench/78895833eaf48b0bf4571e874363ad32 to your computer and use it in GitHub Desktop.
Annotated workflow for publishing deno packages to JSR with Github CI
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
| ## | |
| ## Quick annotated example file to build a Github CI workflow to publish your package to | |
| ## JSR.io whenever you create and publish a new versioned system tag! | |
| ## | |
| name: Publish to JSR | |
| on: | |
| push: | |
| # Runs on creation of tags created of type v.X.Y.Z (eg `tag -a v2.3.21`) | |
| tags: ["v*"] | |
| workflow_dispatch: | |
| # Allows for user to manually trigger a tag publish event | |
| inputs: | |
| tag: | |
| description: "Tag to publish (e.g., v1.0.0)" | |
| required: true | |
| type: string | |
| jobs: | |
| validate: | |
| name: Pre-publish Validation | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Deno | |
| uses: denoland/setup-deno@v1 | |
| with: | |
| deno-version: v2.x | |
| # Gets version from workflow dispatch or tag name | |
| - name: Extract version from tag | |
| id: version | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| VERSION="${{ github.event.inputs.tag }}" | |
| else | |
| VERSION="${GITHUB_REF#refs/tags/}" | |
| fi | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| echo "Publishing version: ${VERSION}" | |
| # Ensure that tag passed matches what you have in the deno.json manifest. | |
| # You could remove this if you want have more control to deploy manually | |
| # and potentially add in something that adds the tag to your deno.json in this flow | |
| - name: Verify version in deno.json matches tag | |
| run: | | |
| DENO_VERSION=$(jq -r '.version' deno.json) | |
| TAG_VERSION="${{ steps.version.outputs.version }}" | |
| TAG_VERSION_CLEAN="${TAG_VERSION#v}" | |
| if [ "$DENO_VERSION" != "$TAG_VERSION_CLEAN" ]; then | |
| echo "Error: Version mismatch!" | |
| echo "deno.json version: $DENO_VERSION" | |
| echo "Tag version: $TAG_VERSION_CLEAN" | |
| exit 1 | |
| fi | |
| # Re-run basic quality checks before we start publishing. Add any other required commands here | |
| - name: Run quality checks | |
| run: | | |
| deno fmt --check | |
| deno lint | |
| deno test | |
| publish: | |
| name: Publish to JSR | |
| runs-on: ubuntu-latest | |
| needs: validate | |
| environment: publishing | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Deno | |
| uses: denoland/setup-deno@v1 | |
| with: | |
| deno-version: v2.x | |
| # This is using the OIDC flow by linking your github repo to your JSR profile, | |
| # you can link it by going to https://jsr.io/@<somescope>/<yourpackagename>/publish to set it up | |
| - name: Publish to JSR | |
| run: deno publish | |
| # Creates a GH release after the package is published from the tag used to publish | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ needs.validate.outputs.version }} | |
| name: Release ${{ needs.validate.outputs.version }} | |
| generate_release_notes: true | |
| draft: false | |
| prerelease: ${{ contains(needs.validate.outputs.version, '-') }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment