Skip to content

Commit 0e7a115

Browse files
committed
cleanup/ci: update publish workflow
Signed-off-by: Dharun Krishna K B <[email protected]>
1 parent de39c7f commit 0e7a115

File tree

2 files changed

+78
-60
lines changed

2 files changed

+78
-60
lines changed

.github/workflows/publish.yml

Lines changed: 75 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,111 @@
1-
# This workflow automatically publishes the package to NPM and GHCR when a new release is created.
2-
# Before, creating a new release, make sure to update the package version in package.json.
1+
# This workflow automatically publishes the package to NPM and GHCR when a new tag is created/pushed.
2+
# Before, tagging a new release, make sure to update the version in package.json file.
33
# The NPM package is published using Trusted Publishers using OIDC (without a PAT) when a release is created
44
# and the deployment is approved by an admin.
55

6-
name: Publish
6+
7+
name: Publish Release
78
on:
8-
release:
9-
types: [published]
10-
workflow_dispatch:
9+
push:
10+
tags:
11+
- 'v*'
12+
1113

1214
jobs:
15+
create-release:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write # Required to create a release
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Create GitHub Release with changelog
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
run: |
26+
TAG_NAME=${GITHUB_REF#refs/tags/}
27+
gh release create "$TAG_NAME" --generate-notes --title "$TAG_NAME" --verify-tag || echo "Release may already exist."
28+
1329
publish-npm:
1430
runs-on: ubuntu-latest
15-
name: npm
31+
needs: create-release
1632

1733
environment:
1834
name: npm
1935
url: https://www.npmjs.com/package/tldr-lint
20-
36+
2137
permissions:
2238
contents: read
2339
id-token: write # Required for OIDC in NPM Trusted Publishing
2440

2541
steps:
2642
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2743

28-
# Setup .npmrc file to publish to npm
2944
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
3045
with:
3146
node-version: '22.x'
3247
registry-url: 'https://registry.npmjs.org'
3348

3449
- run: npm ci
35-
- run: npm publish --access public
50+
- run: npm publish
3651

3752
publish-ghcr:
3853
runs-on: ubuntu-latest
39-
54+
needs: create-release
4055
permissions:
4156
contents: read
4257
packages: write # Allow pushing images to GHCR
43-
attestations: write # To create and write attestations
58+
attestations: write # Required to create and write attestations
4459
id-token: write # Additional permissions for the persistence of the attestations
45-
60+
4661
env:
4762
BUILDX_NO_DEFAULT_ATTESTATIONS: 1
4863

4964
steps:
50-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
51-
52-
- name: Set image name
53-
run: |
54-
echo "IMAGE_URL=ghcr.io/tldr-pages/tldr-lint">> "$GITHUB_ENV"
55-
56-
- name: Docker meta
57-
id: docker_meta
58-
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
59-
with:
60-
images: |
61-
${{ env. IMAGE_URL }}
62-
tags: |
63-
type=raw,value=latest
64-
65-
- name: Set up Docker Buildx
66-
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
67-
68-
- name: Login to GitHub Package Registry
69-
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
70-
with:
71-
registry: ghcr.io
72-
username: ${{ github.repository_owner }}
73-
password: ${{ secrets.GITHUB_TOKEN }}
74-
75-
- name: Build and Push the Docker image
76-
id: push
77-
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
78-
with:
79-
context: .
80-
file: Dockerfile
81-
push: true
82-
tags: ${{ steps.docker_meta.outputs.tags }}
83-
labels: ${{ steps.docker_meta.outputs.labels }}
84-
cache-from: type=gha
85-
cache-to: type=gha,mode=max
86-
platforms: linux/amd64
87-
provenance: false
88-
89-
- name: Attest pushed image
90-
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.4.0
91-
id: attest
92-
with:
93-
subject-name: ${{ env.IMAGE_URL }}
94-
subject-digest: ${{ steps.push.outputs.digest }}
95-
push-to-registry: false
65+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
66+
67+
- name: Set image name
68+
run: |
69+
echo "IMAGE_URL=ghcr.io/tldr-pages/tldr-lint">> "$GITHUB_ENV"
70+
71+
- name: Docker meta
72+
id: docker_meta
73+
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
74+
with:
75+
images: |
76+
${{ env.IMAGE_URL }}
77+
tags: |
78+
type=raw,value=latest
79+
type=raw,value=${{ github.ref_name }}
80+
81+
- name: Set up Docker Buildx
82+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
83+
84+
- name: Login to GitHub Package Registry
85+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
86+
with:
87+
registry: ghcr.io
88+
username: ${{ github.repository_owner }}
89+
password: ${{ secrets.GITHUB_TOKEN }}
90+
91+
- name: Build and Push the Docker image
92+
id: push
93+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
94+
with:
95+
context: .
96+
file: Dockerfile
97+
push: true
98+
tags: ${{ steps.docker_meta.outputs.tags }}
99+
labels: ${{ steps.docker_meta.outputs.labels }}
100+
cache-from: type=gha
101+
cache-to: type=gha,mode=max
102+
platforms: linux/amd64
103+
provenance: false
104+
105+
- name: Attest pushed image
106+
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.4.0
107+
id: attest
108+
with:
109+
subject-name: ${{ env.IMAGE_URL }}
110+
subject-digest: ${{ steps.push.outputs.digest }}
111+
push-to-registry: false

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
"pages",
2525
"lint",
2626
"validate",
27-
"format"
27+
"format",
28+
"linter"
2829
],
30+
"homepage": "https://tldr.sh",
2931
"author": {
3032
"name": "Ruben Vereecken",
3133
"email": "[email protected]"

0 commit comments

Comments
 (0)