|
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. |
3 | 3 | # The NPM package is published using Trusted Publishers using OIDC (without a PAT) when a release is created |
4 | 4 | # and the deployment is approved by an admin. |
5 | 5 |
|
6 | | -name: Publish |
| 6 | + |
| 7 | +name: Publish Release |
7 | 8 | on: |
8 | | - release: |
9 | | - types: [published] |
10 | | - workflow_dispatch: |
| 9 | + push: |
| 10 | + tags: |
| 11 | + - 'v*' |
| 12 | + |
11 | 13 |
|
12 | 14 | 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 | +
|
13 | 29 | publish-npm: |
14 | 30 | runs-on: ubuntu-latest |
15 | | - name: npm |
| 31 | + needs: create-release |
16 | 32 |
|
17 | 33 | environment: |
18 | 34 | name: npm |
19 | 35 | url: https://www.npmjs.com/package/tldr-lint |
20 | | - |
| 36 | + |
21 | 37 | permissions: |
22 | 38 | contents: read |
23 | 39 | id-token: write # Required for OIDC in NPM Trusted Publishing |
24 | 40 |
|
25 | 41 | steps: |
26 | 42 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
27 | 43 |
|
28 | | - # Setup .npmrc file to publish to npm |
29 | 44 | - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
30 | 45 | with: |
31 | 46 | node-version: '22.x' |
32 | 47 | registry-url: 'https://registry.npmjs.org' |
33 | 48 |
|
34 | 49 | - run: npm ci |
35 | | - - run: npm publish --access public |
| 50 | + - run: npm publish |
36 | 51 |
|
37 | 52 | publish-ghcr: |
38 | 53 | runs-on: ubuntu-latest |
39 | | - |
| 54 | + needs: create-release |
40 | 55 | permissions: |
41 | 56 | contents: read |
42 | 57 | packages: write # Allow pushing images to GHCR |
43 | | - attestations: write # To create and write attestations |
| 58 | + attestations: write # Required to create and write attestations |
44 | 59 | id-token: write # Additional permissions for the persistence of the attestations |
45 | | - |
| 60 | + |
46 | 61 | env: |
47 | 62 | BUILDX_NO_DEFAULT_ATTESTATIONS: 1 |
48 | 63 |
|
49 | 64 | 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 |
0 commit comments