Publish #10
Workflow file for this run
This file contains 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
# This workflow automatically publishes the package to NPM and GHCR when a new release is created. | |
# Before, creating a new release, make sure to update the package version in package.json | |
# and add a Granular Access Token (with read and write packages scope) | |
# to the repository secrets with the name NPM_TOKEN. | |
# Once, the release has been published remove it from the repository secrets. | |
name: Publish | |
on: | |
release: | |
types: [published] | |
workflow_dispatch: | |
jobs: | |
publish-npm: | |
runs-on: ubuntu-latest | |
name: npm | |
permissions: | |
contents: read | |
id-token: write | |
steps: | |
- uses: actions/checkout@v4 | |
# Setup .npmrc file to publish to npm | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '20.x' | |
registry-url: 'https://registry.npmjs.org' | |
- run: npm ci | |
- run: npm publish --provenance | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
publish-ghcr: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write # Allow pushing images to GHCR | |
attestations: write # To create and write attestations | |
id-token: write # Additional permissions for the persistence of the attestations | |
env: | |
BUILDX_NO_DEFAULT_ATTESTATIONS: 1 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set image name | |
run: | | |
echo "IMAGE_URL=ghcr.io/tldr-pages/tldr-lint">> "$GITHUB_ENV" | |
- name: Docker meta | |
id: docker_meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
${{ env. IMAGE_URL }} | |
tags: | | |
type=raw,value=latest | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Package Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and Push the Docker image | |
id: push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: Dockerfile | |
push: true | |
tags: ${{ steps.docker_meta.outputs.tags }} | |
labels: ${{ steps.docker_meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
platforms: linux/amd64 | |
provenance: false | |
- name: Attest pushed image | |
uses: actions/attest-build-provenance@v2 | |
id: attest | |
with: | |
subject-name: ${{ env.IMAGE_URL }} | |
subject-digest: ${{ steps.push.outputs.digest }} | |
push-to-registry: false |