Skip to content

Commit 34dead4

Browse files
KyrylRArvolear
andauthored
Improved package publishing process (#155)
* Improved package publishing process * Small refactoring * Replaced main to master * More of cleaning up * Fixes after review * CI update * Fixed typo * Updated PULL_REQUEST_TEMPLATE.md * refactor and add contributing.md * add docs --------- Co-authored-by: Artem Chystiakov <artem.ch31@gmail.com>
1 parent 39c1655 commit 34dead4

19 files changed

+576
-44
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<!--
22
Thank you for contributing to Solarity!
33
4-
Please consider ticking the relevant statements.
4+
Before opening a pull request, please check out the contributing guidelines.
5+
6+
Make sure that the CHANGELOG.md is up to date and consider ticking the relevant statements below.
57
-->
68

79
- [ ] Since this PR suggests a **bug fix**, the tests have been added and the coverage is 100%.
@@ -10,5 +12,4 @@ Please consider ticking the relevant statements.
1012

1113
---
1214

13-
1415
<!-- Add the PR description here. -->

.github/actions/setup/action.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ runs:
44
using: composite
55
steps:
66
- name: Setup node
7-
uses: actions/setup-node@v3
7+
uses: actions/setup-node@v4
88
with:
9-
node-version: "18.18.x"
9+
node-version: "20.x"
1010
cache: npm
11+
registry-url: 'https://registry.npmjs.org/'
12+
1113
- name: Install packages
1214
run: npm install
1315
shell: bash
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: changelog-validate
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
- dev
8+
9+
jobs:
10+
validate:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Setup
17+
uses: ./.github/actions/setup
18+
19+
- name: Validate structure
20+
run: npx tsx scripts/release/validate-changelog.ts

.github/workflows/pre-release.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: pre-release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
concurrency: ${{ github.workflow }}-${{ github.ref }}
9+
10+
jobs:
11+
validate:
12+
name: Validate CHANGELOG
13+
runs-on: ubuntu-latest
14+
if: ${{ !contains(github.event.head_commit.message, 'chore(release):') }}
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Setup
19+
uses: ./.github/actions/setup
20+
21+
- name: Validate structure
22+
run: npx tsx scripts/release/validate-changelog.ts
23+
24+
pre-release:
25+
name: Apply version and tag
26+
needs: validate
27+
runs-on: ubuntu-latest
28+
if: ${{ !contains(github.event.head_commit.message, 'chore(release):') }}
29+
permissions:
30+
contents: write
31+
id-token: write
32+
steps:
33+
- uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 0
36+
37+
- name: Setup
38+
uses: ./.github/actions/setup
39+
40+
- id: apply
41+
name: Compute and apply next version
42+
uses: actions/github-script@v7
43+
with:
44+
script: |
45+
require('ts-node/register/transpile-only');
46+
await require('./scripts/release/apply-release.ts').default(core);
47+
48+
- run: bash scripts/git-user-config.sh
49+
- name: Commit version bump and changelog update
50+
if: steps.apply.outputs.skip != 'true'
51+
run: |
52+
git add package.json package-lock.json CHANGELOG.md
53+
if ! git diff --cached --quiet; then
54+
git commit -m "chore(release): v${{ steps.apply.outputs.version }}"
55+
git tag v${{ steps.apply.outputs.version }}
56+
git push origin HEAD:main
57+
git push origin HEAD:main --tags
58+
fi

.github/workflows/release.yml

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
workflow_run:
66
workflows:
77
- tests
8+
- pre-release
89
types:
910
- completed
1011
branches:
@@ -16,48 +17,61 @@ jobs:
1617
if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success'
1718
steps:
1819
- name: Checkout the repository
19-
uses: actions/checkout@v3
20+
uses: actions/checkout@v4
21+
2022
- name: Set up environment
2123
uses: ./.github/actions/setup
22-
- name: Fetch State
23-
id: state
24-
run: bash ./scripts/versions.sh
24+
25+
- id: state
26+
name: Compute release state
27+
uses: actions/github-script@v7
28+
with:
29+
result-encoding: string
30+
script: |
31+
require('ts-node/register/transpile-only');
32+
await require('./scripts/release/get-release-state.ts').default(core);
2533
outputs:
2634
local_version: ${{ steps.state.outputs.local_version }}
27-
version_changed: ${{ steps.state.outputs.version_changed }}
35+
notes: ${{ steps.state.outputs.notes }}
36+
is_release_commit: ${{ steps.state.outputs.is_release_commit }}
2837

2938
release:
3039
runs-on: ubuntu-latest
3140
needs: state
32-
if: needs.state.outputs.version_changed != 'not_changed'
41+
if: needs.state.outputs.is_release_commit == 'true'
3342
steps:
3443
- name: Checkout the repository
35-
uses: actions/checkout@v3
44+
uses: actions/checkout@v4
3645
- name: Create Release
3746
uses: softprops/action-gh-release@v2
3847
with:
3948
token: ${{ secrets.ARVOLEAR_RELEASER }}
40-
tag_name: ${{ needs.state.outputs.local_version }}
49+
tag_name: v${{ needs.state.outputs.local_version }}
4150
name: Release v${{ needs.state.outputs.local_version }}
4251
body: |
4352
# Release notes v${{ needs.state.outputs.local_version }} 🎉
44-
45-
## This is a ${{ needs.state.outputs.version_changed }} release
46-
47-
To be filled...
53+
54+
${{ needs.state.outputs.notes }}
4855
draft: false
4956
prerelease: false
5057

5158
publish:
5259
runs-on: ubuntu-latest
5360
needs: state
54-
if: needs.state.outputs.version_changed != 'not_changed'
61+
if: needs.state.outputs.is_release_commit == 'true'
5562
steps:
5663
- name: Checkout the repository
57-
uses: actions/checkout@v3
58-
- name: Setup
64+
uses: actions/checkout@v4
65+
66+
- name: Set up environment
5967
uses: ./.github/actions/setup
68+
69+
- name: Install packages
70+
run: npm install
71+
shell: bash
72+
6073
- name: Publish to npm
61-
run: |
62-
npm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_ACCESS_TOKEN }}
63-
npm run publish-to-npm
74+
run: npm run publish-to-npm
75+
env:
76+
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
77+

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## [none]
4+
5+
- Improved package publishing process

CONTRIBUTING.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Contributing Guidelines
2+
3+
You are more than welcome to contribute to Solarity library as we are warmly open to any mind-blowing ideas!
4+
5+
## Issues
6+
7+
If you found a minor bug, interested in a new feature, or just have any questions, please [open an issue](https://github.com/dl-solarity/solidity-lib/issues/new/choose). For major bugs, please reach out to the team directly.
8+
9+
Before opening an issue, confirm that there is no duplicate (either open or closed), and consider posting a comment there instead.
10+
11+
When submitting a feature request, please provide as many details as possible for the team to properly understand the feature's motivation and evaluate the impact.
12+
13+
## Pull Requests
14+
15+
If you're interested in contributing code to the library, start by [forking the repository](https://github.com/dl-solarity/solidity-lib/fork) and submitting a pull request.
16+
17+
But before you start coding, we highly recommend that you [open an issue](https://github.com/dl-solarity/solidity-lib/issues/new/choose) first to discuss the changes you want to make.
18+
19+
Additionally, please make sure to thoroughly read the [Solidity](https://docs.solarity.dev/docs/getting-started/contribution/solidity) and [Tests](https://docs.solarity.dev/docs/getting-started/contribution/tests) guidelines. Following these guidelines is crucial for maintaining the quality and consistency of the codebase.
20+
21+
## Disclaimer
22+
23+
Please don't vibe code smart contract.

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![npm](https://img.shields.io/npm/v/@solarity/solidity-lib.svg)](https://www.npmjs.com/package/@solarity/solidity-lib)
44
[![Coverage Status](https://codecov.io/gh/dl-solarity/solidity-lib/graph/badge.svg)](https://codecov.io/gh/dl-solarity/solidity-lib)
55
[![Tests](https://github.com/dl-solarity/solidity-lib/actions/workflows/tests.yml/badge.svg)](https://github.com/dl-solarity/solidity-lib/actions/workflows/tests.yml)
6+
[![Docs](https://img.shields.io/badge/docs-%F0%9F%93%84-yellow)](https://docs.solarity.dev/)
67
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
78
[![GitPOAP Badge](https://public-api.gitpoap.io/v1/repo/dl-solarity/solidity-lib/badge)](https://www.gitpoap.io/gh/dl-solarity/solidity-lib)
89

@@ -107,9 +108,9 @@ The latest stable version is always in the `master` branch.
107108

108109
Check out the project's [documentation](https://docs.solarity.dev) with broad explanations and usage examples of every contract. Full `natspec` guides are also available in the source code.
109110

110-
## Contribution
111+
## Contributing
111112

112-
We are open to any mind-blowing ideas! Please take a look at our [contribution guidelines](https://docs.solarity.dev/docs/getting-started/contribution/how-to-contribute) to get involved.
113+
We are open to any mind-blowing ideas! Please take a look at our [contributing guidelines](CONTRIBUTING.md) to get involved.
113114

114115
## License
115116

scripts/git-user-config.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail -x
4+
5+
git config user.name 'github-actions'
6+
git config user.email 'actions@github.com'

scripts/release/apply-release.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env node
2+
3+
import fs from "fs";
4+
5+
import computeNextVersion from "./helpers/compute-next-version";
6+
7+
import { getTopSection, readJSON, writeJSON, getPkgPath, getChangelogPath, validateReleaseTopSection } from "./helpers";
8+
9+
import type { Core } from "./helpers";
10+
11+
export default async function applyRelease(core: Core): Promise<void> {
12+
const pkgPath = getPkgPath();
13+
const changelogPath = getChangelogPath();
14+
15+
const pkg = readJSON<{ version: string }>(pkgPath);
16+
const changelog = fs.readFileSync(changelogPath, "utf8");
17+
18+
const { level, body, start } = getTopSection(changelog);
19+
const pkgIsRc = /-rc\.\d+$/.test(pkg.version);
20+
21+
validateReleaseTopSection({ level, body, pkgIsRc });
22+
23+
if (level === "none") {
24+
core.setOutput("skip", String(true));
25+
core.setOutput("version", pkg.version);
26+
core.setOutput("notes", body);
27+
return;
28+
}
29+
30+
const { next } = computeNextVersion();
31+
32+
// Update package.json version
33+
writeJSON(pkgPath, { ...pkg, version: next });
34+
35+
// Rewrite top section heading to the new version number
36+
const lines = changelog.split(/\r?\n/);
37+
38+
if (start >= 0) {
39+
lines[start] = `## [${next}]`;
40+
}
41+
42+
fs.writeFileSync(changelogPath, `${lines.join("\n")}\n`);
43+
44+
core.setOutput("skip", String(false));
45+
core.setOutput("version", next);
46+
core.setOutput("notes", body);
47+
48+
return;
49+
}

0 commit comments

Comments
 (0)