Skip to content

Commit 900ccc8

Browse files
committed
chore: update Hardhat configuration and CI workflows
- Added conditional loading of tasks in hardhat.config.cts based on SKIP_HARDHAT_TASKS environment variable. - Updated package.json to reflect new Mocha version and adjusted test script formatting. - Enhanced CI workflows to include conditional steps for local testing with ACT environment variable, ensuring proper dependency installation and task execution. - Added compilation and testing steps in CI workflows with SKIP_HARDHAT_TASKS environment variable for better control over task execution.
1 parent f1439ec commit 900ccc8

File tree

4 files changed

+138
-15
lines changed

4 files changed

+138
-15
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,37 @@ jobs:
2121
version: 9
2222
run_install: false
2323

24+
- name: Setup Node.js (act)
25+
if: env.ACT == 'true'
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: '22'
29+
2430
- name: Setup Node.js
31+
if: env.ACT != 'true'
2532
uses: actions/setup-node@v4
2633
with:
2734
node-version: '22'
2835
cache: 'pnpm'
29-
cache-dependency-path: pnpm-lock.yaml
36+
cache-dependency-path: '**/pnpm-lock.yaml'
37+
38+
- name: Install dependencies (act)
39+
if: env.ACT == 'true'
40+
run: pnpm install --no-frozen-lockfile
3041

3142
- name: Install dependencies
43+
if: env.ACT != 'true'
3244
run: pnpm install --frozen-lockfile
3345

46+
- name: Compile contracts
47+
run: pnpm hardhat compile
48+
env:
49+
SKIP_HARDHAT_TASKS: "true"
50+
3451
- name: Build
3552
run: pnpm run build
3653

3754
- name: Test
3855
run: pnpm test
56+
env:
57+
SKIP_HARDHAT_TASKS: "true"

.github/workflows/release.yml

Lines changed: 112 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,65 +18,167 @@ jobs:
1818
permissions:
1919
contents: write
2020
id-token: write
21+
concurrency:
22+
group: release-${{ github.ref_name }}
23+
cancel-in-progress: false
2124
steps:
2225
- name: Checkout
2326
uses: actions/checkout@v4
2427
with:
2528
fetch-depth: 0
29+
fetch-tags: true
2630

2731
- name: Setup pnpm
2832
uses: pnpm/action-setup@v4
2933
with:
3034
version: 9
3135

36+
- name: Setup Node.js (act)
37+
if: ${{ env.ACT == 'true' }}
38+
uses: actions/setup-node@v4
39+
with:
40+
node-version: '22'
41+
registry-url: 'https://registry.npmjs.org/'
42+
3243
- name: Setup Node.js
44+
if: ${{ env.ACT != 'true' }}
3345
uses: actions/setup-node@v4
3446
with:
3547
node-version: '22'
3648
cache: 'pnpm'
37-
cache-dependency-path: pnpm-lock.yaml
49+
cache-dependency-path: '**/pnpm-lock.yaml'
3850
registry-url: 'https://registry.npmjs.org/'
3951

52+
- name: Install dependencies (act)
53+
if: ${{ env.ACT == 'true' }}
54+
run: pnpm install --no-frozen-lockfile
55+
4056
- name: Install dependencies
57+
if: ${{ env.ACT != 'true' }}
4158
run: pnpm install --frozen-lockfile
4259

60+
- name: Compile contracts
61+
if: ${{ env.ACT != 'true' }}
62+
run: pnpm hardhat compile
63+
env:
64+
SKIP_HARDHAT_TASKS: "true"
65+
66+
- name: Run tests
67+
if: ${{ env.ACT != 'true' }}
68+
run: pnpm test
69+
env:
70+
SKIP_HARDHAT_TASKS: "true"
71+
4372
- name: Compute version
4473
id: version
74+
shell: bash
4575
run: |
76+
set -euo pipefail
4677
INPUT_VERSION="${{ github.event.inputs.version }}"
78+
CHANNEL="${{ github.event.inputs.dist_tag }}"
79+
SHORT_SHA=$(git rev-parse --short HEAD)
4780
if [ -n "$INPUT_VERSION" ]; then
4881
echo "version=$INPUT_VERSION" >> "$GITHUB_OUTPUT"
4982
exit 0
5083
fi
51-
LATEST=$(git tag -l 'v*' | sort --version-sort | tail -n 1)
84+
if [ "$CHANNEL" != "latest" ] && [ -n "$CHANNEL" ]; then
85+
BASE_VERSION=$(node -p "require('./package.json').version")
86+
NEXT="v${BASE_VERSION}-${CHANNEL}.${SHORT_SHA}"
87+
echo "version=$NEXT" >> "$GITHUB_OUTPUT"
88+
exit 0
89+
fi
90+
LATEST=$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' | sort -V | tail -n 1 || true)
5291
if [ -z "$LATEST" ]; then
53-
NEXT="v0.1.0-beta"
92+
BASE_VERSION=$(node -p "require('./package.json').version")
93+
NEXT="v${BASE_VERSION}"
5494
else
5595
BASE=${LATEST#v}
5696
NEXT="v$(npx --yes semver -i patch "$BASE")"
5797
fi
5898
echo "version=$NEXT" >> "$GITHUB_OUTPUT"
5999
60100
- name: Update package version
61-
run: pnpm version $(echo ${{ steps.version.outputs.version }} | sed 's/^v//') --no-git-tag-version
101+
run: pnpm version "$(echo "${{ steps.version.outputs.version }}" | sed 's/^v//')" --no-git-tag-version
62102

63103
- name: Build
64104
run: pnpm run build
65105

106+
- name: Ensure version not already on npm
107+
if: ${{ env.ACT != 'true' }}
108+
shell: bash
109+
run: |
110+
set -euo pipefail
111+
PKG_NAME=$(node -p "require('./package.json').name")
112+
VERSION=$(echo "${{ steps.version.outputs.version }}" | sed 's/^v//')
113+
if npm view "$PKG_NAME@$VERSION" version >/dev/null 2>&1; then
114+
echo "Version $VERSION is already published to npm. Aborting."
115+
exit 1
116+
fi
117+
66118
- name: Publish to npm
119+
if: ${{ env.ACT != 'true' }}
67120
env:
68121
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
69-
run: pnpm publish --tag ${{ github.event.inputs.dist_tag }} --access public --no-git-checks
122+
shell: bash
123+
run: |
124+
set -euo pipefail
125+
pnpm publish --tag "${{ github.event.inputs.dist_tag }}" --access public --provenance --no-git-checks
126+
127+
- name: Commit version bump
128+
if: ${{ env.ACT != 'true' }}
129+
env:
130+
VERSION: ${{ steps.version.outputs.version }}
131+
BRANCH: ${{ github.ref_name }}
132+
GIT_AUTHOR_NAME: github-actions[bot]
133+
GIT_AUTHOR_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
134+
GIT_COMMITTER_NAME: github-actions[bot]
135+
GIT_COMMITTER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
136+
shell: bash
137+
run: |
138+
set -euo pipefail
139+
git add package.json pnpm-lock.yaml || true
140+
if git diff --cached --quiet; then
141+
echo "No version changes to commit"
142+
else
143+
git commit -m "chore(release): $VERSION [skip ci]"
144+
git push origin HEAD:refs/heads/$BRANCH
145+
fi
146+
147+
- name: Ensure git tag does not already exist
148+
if: ${{ env.ACT != 'true' }}
149+
shell: bash
150+
run: |
151+
set -euo pipefail
152+
TAG="${{ steps.version.outputs.version }}"
153+
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
154+
echo "Git tag $TAG already exists locally."
155+
exit 1
156+
fi
157+
if git ls-remote --tags origin "refs/tags/$TAG" | grep -q .; then
158+
echo "Git tag $TAG already exists on origin."
159+
exit 1
160+
fi
70161
71162
- name: Create git tag
163+
if: ${{ env.ACT != 'true' }}
164+
shell: bash
72165
run: |
73-
git tag ${{ steps.version.outputs.version }}
74-
git push origin ${{ steps.version.outputs.version }}
166+
set -euo pipefail
167+
git tag -a "${{ steps.version.outputs.version }}" -m "Release ${{ steps.version.outputs.version }}"
168+
git push origin "${{ steps.version.outputs.version }}"
75169
76170
- name: Create GitHub release
171+
if: ${{ env.ACT != 'true' }}
77172
env:
78173
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
174+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
175+
shell: bash
79176
run: |
80-
gh release create ${{ steps.version.outputs.version }} \
81-
--title ${{ steps.version.outputs.version }} \
82-
--generate-notes
177+
set -euo pipefail
178+
PRERELEASE_FLAG=""
179+
if [[ "${{ github.event.inputs.dist_tag }}" != "latest" && -n "${{ github.event.inputs.dist_tag }}" ]]; then
180+
PRERELEASE_FLAG="--prerelease"
181+
fi
182+
gh release create "${{ steps.version.outputs.version }}" \
183+
--title "${{ steps.version.outputs.version }}" \
184+
--generate-notes $PRERELEASE_FLAG

hardhat.config.cts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import "@nomicfoundation/hardhat-chai-matchers";
1010
import "hardhat-switch-network";
1111

1212

13-
import './tasks'
13+
if (process.env.SKIP_HARDHAT_TASKS !== "true") {
14+
require("./tasks");
15+
}
1416

1517
subtask(TASK_COMPILE_SOLIDITY).setAction(async (_, { config }, runSuper) => {
1618
const superRes = await runSuper();

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"clean": "rm -rf dist",
1414
"build": "tsc -p tsconfig.build.json",
1515
"prepare": "pnpm run build",
16-
"test": "hardhat test test/attestation/TrufAttestation.test.ts test/attestation/TrufAttestationConsumer.test.ts"
16+
"test": "hardhat test test/attestation/TrufAttestation.test.ts test/attestation/TrufAttestationConsumer.test.ts"
1717
},
1818
"dependencies": {
1919
"@chainlink/functions-toolkit": "0.3.2",
@@ -33,14 +33,14 @@
3333
"@types/chai": "^4.3.0",
3434
"@types/chai-as-promised": "7.1.2",
3535
"@types/inquirer": "^9.0.7",
36-
"@types/mocha": "^9.1.0",
36+
"@types/mocha": "^10.0.10",
3737
"@types/node": "20.11.18",
3838
"chai": "4.3.7",
3939
"chai-as-promised": "7.1.2",
4040
"dotenv": "16.4.5",
4141
"hardhat": "2.22.16",
4242
"hardhat-switch-network": "1.1.1",
43-
"mocha": "11.0.1",
43+
"mocha": "^11.7.4",
4444
"prettier": "^3.3.3",
4545
"semver": "^7.7.3",
4646
"solidity-coverage": "^0.8.0",

0 commit comments

Comments
 (0)