@daiyam/artifact-npm 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ // Get version from command line argument (with 'v' prefix)
5
+ const version = process.argv[2];
6
+
7
+ try {
8
+ const changelog = fs.readFileSync(path.join(process.cwd(), 'CHANGELOG.md'), 'utf8');
9
+
10
+ // Regular expression to match a version section with the date
11
+ // Matches from "## v0.8.1 | 2025-04-23" until the next ## or end of file
12
+ const versionRegex = new RegExp(`## ${version} \\| \\d{4}-\\d{2}-\\d{2}[^#]*(?=## |$)`, 's');
13
+
14
+ const match = changelog.match(versionRegex);
15
+
16
+ if(match) {
17
+ // Remove the version header and trim whitespace
18
+ const notes = match[0].replace(/^## v\d+\.\d+\.\d+ \| \d{4}-\d{2}-\d{2}\n/, '').trim();
19
+ console.log(notes);
20
+ process.exit(0);
21
+ }
22
+ else {
23
+ console.error(`No changelog entry found for version ${version}`);
24
+ process.exit(1);
25
+ }
26
+ }
27
+ catch(error) {
28
+ console.error('Error reading CHANGELOG.md:', error);
29
+ process.exit(1);
30
+ }
@@ -1,19 +1,99 @@
1
1
  name: Publish Package
2
2
  on:
3
- workflow_dispatch:
3
+ workflow_dispatch: null
4
4
  push:
5
5
  tags:
6
- - "v*"
6
+ - v*
7
7
  permissions:
8
- id-token: write
8
+ id-token: write # NPM
9
+ contents: write # Release
9
10
  jobs:
10
11
  publish:
11
12
  runs-on: ubuntu-latest
12
13
  steps:
13
- - uses: actions/checkout@v6
14
- - uses: actions/setup-node@v6
14
+ - name: Checkout code
15
+ uses: actions/checkout@v6
15
16
  with:
16
- node-version: '24'
17
+ fetch-depth: 0
18
+ - name: Get Version
19
+ run: |
20
+ # Get the latest tag
21
+ LATEST_TAG=$(git tag --sort=-v:refname | head -n1)
22
+ if [ -z "$LATEST_TAG" ]; then
23
+ echo "No tags found in the repository"
24
+ exit 1
25
+ fi
26
+ echo "VERSION=$LATEST_TAG" >> $GITHUB_ENV
27
+ echo "Using version: $LATEST_TAG"
28
+ - name: Check Existing Release
29
+ run: |
30
+ # Try to get the release information
31
+ RELEASE_INFO=$(gh release view ${{ env.VERSION }} --json assets,url 2>/dev/null || echo "")
32
+ if [ ! -z "$RELEASE_INFO" ]; then
33
+ echo "Release exists"
34
+ echo "RELEASE_EXISTS=yes" >> $GITHUB_ENV
35
+ # Get the TGZ asset URL from the release
36
+ TGZ_URL=$(echo $RELEASE_INFO | jq -r '.assets[] | select(.name | endswith(".tgz")) | .url')
37
+ if [ ! -z "$TGZ_URL" ]; then
38
+ echo "Found existing TGZ file"
39
+ echo "TGZ_URL=$TGZ_URL" >> $GITHUB_ENV
40
+ echo "TGZ_NAME=$(echo $RELEASE_INFO | jq -r '.assets[] | select(.name | endswith(".tgz")) | .name')" >> $GITHUB_ENV
41
+ fi
42
+ else
43
+ echo "RELEASE_EXISTS=no" >> $GITHUB_ENV
44
+ fi
45
+ env:
46
+ GH_TOKEN: ${{ github.token }}
47
+ - name: Download Existing TGZ
48
+ if: env.RELEASE_EXISTS == 'yes' && env.TGZ_URL != ''
49
+ run: |
50
+ gh api ${{ env.TGZ_URL }} --header 'Accept: application/octet-stream' > ${{ env.TGZ_NAME }}
51
+ echo "CHECKSUM=$(sha256sum ${{ env.TGZ_NAME }} | cut -d ' ' -f 1)" >> $GITHUB_ENV
52
+ env:
53
+ GH_TOKEN: ${{ github.token }}
54
+ - name: Setup Node.js
55
+ if: env.RELEASE_EXISTS == 'no'
56
+ uses: actions/setup-node@v6
57
+ with:
58
+ node-version: "24"
17
59
  registry-url: https://registry.npmjs.org
18
- - run: npm ci
19
- - run: npm publish --access=public
60
+ - name: Build
61
+ if: env.RELEASE_EXISTS == 'no'
62
+ run: |
63
+ npm ci
64
+ npm pack
65
+ TGZ_NAME=$(ls *.tgz)
66
+ CHECKSUM=$(sha256sum $TGZ_NAME | cut -d ' ' -f 1)
67
+ echo "TGZ_NAME=$TGZ_NAME" >> $GITHUB_ENV
68
+ echo "CHECKSUM=$CHECKSUM" >> $GITHUB_ENV
69
+ echo "$CHECKSUM" > "$TGZ_NAME.sha256"
70
+ - name: Get Changelog
71
+ if: env.RELEASE_EXISTS == 'no'
72
+ run: |
73
+ CHANGELOG_ENTRY=$(node .github/scripts/get-changelog.js ${{ env.VERSION }})
74
+ # Properly handle multiline output in GitHub Actions
75
+ EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
76
+ echo "CHANGELOG_ENTRY<<$EOF" >> $GITHUB_ENV
77
+ echo "$CHANGELOG_ENTRY" >> $GITHUB_ENV
78
+ echo "$EOF" >> $GITHUB_ENV
79
+ - name: Release
80
+ if: env.RELEASE_EXISTS == 'no'
81
+ uses: softprops/action-gh-release@v2
82
+ with:
83
+ files: |
84
+ ${{ env.TGZ_NAME }}
85
+ ${{ env.TGZ_NAME }}.sha256
86
+ name: ${{ env.VERSION }}
87
+ tag_name: ${{ env.VERSION }}
88
+ body: |
89
+ Release ${{ env.VERSION }}
90
+
91
+ ## What's Changed
92
+ ${{ env.CHANGELOG_ENTRY }}
93
+
94
+ ## Checksum (SHA-256)
95
+ ```
96
+ ${{ env.CHECKSUM }}
97
+ ```
98
+ - name: Publish to NPM Registry
99
+ run: npm publish --access=public
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daiyam/artifact-npm",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "The configuration to create node modules and publish them on npm.",
5
5
  "author": {
6
6
  "name": "Baptiste Augrain",
@@ -31,5 +31,5 @@
31
31
  "project-template",
32
32
  "scaffold"
33
33
  ],
34
- "gitHead": "42b37a747e74589c95b7f29be2d55fbd354ab086"
34
+ "gitHead": "fc2c3cc65133f807a8e55906d02787a796cfc46f"
35
35
  }