Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"changelog": false,
"changelog": "@changesets/changelog-git",
"bumpVersionsWithWorkspaceProtocolOnly": true,
"privatePackages": {
"version": true,
Expand Down
108 changes: 108 additions & 0 deletions .github/workflows/release-packages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Create package releases

permissions:
contents: write

on:
push:
tags:
- "js/**"
- "python/**"

jobs:
release:
name: Publish GitHub release for npm package
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check if release already exists
id: release_check
uses: actions/github-script@v7
with:
github-token: ${{ secrets.RELEASE_GH_TOKEN }}
script: |
const tag = context.ref.replace('refs/tags/', '');
try {
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag,
});
core.notice(`Release already exists: ${release.data.html_url}`);
core.setOutput('exists', 'true');
} catch (error) {
if (error.status === 404) {
core.setOutput('exists', 'false');
} else {
throw error;
}
}

- name: Build release body from package CHANGELOG
id: release_body
if: ${{ steps.release_check.outputs.exists != 'true' }}
shell: bash
run: |
set -euo pipefail

tag="${GITHUB_REF_NAME}"
body_file="${RUNNER_TEMP}/release-body.md"

if [[ "$tag" != *"@"* ]]; then
echo "Invalid tag '${tag}': missing '@<version>' suffix" >&2
exit 1
fi

version="${tag##*@}"
changelog_path=""

if [[ "$tag" == js/* ]]; then
pkg_and_version="${tag#js/}"
pkg_name="${pkg_and_version%@*}"
scoped_name="@human-protocol/${pkg_name}"
pkg_json=$(grep -R --include package.json -n "\"name\": \"${scoped_name}\"" packages | head -n 1 | cut -d: -f1 || true)
if [[ -n "$pkg_json" ]]; then
changelog_path="$(dirname "$pkg_json")/CHANGELOG.md"
fi
elif [[ "$tag" == python/* ]]; then
changelog_path="packages/sdk/python/human-protocol-sdk/CHANGELOG.md"
fi

if [[ -z "$changelog_path" ]]; then
echo "Unable to resolve CHANGELOG.md path for tag '${tag}'" >&2
exit 1
fi

if [[ ! -f "$changelog_path" ]]; then
echo "CHANGELOG.md not found at '${changelog_path}' for tag '${tag}'" >&2
exit 1
fi

# Extract the section for the exact version in the tag.
section_body=$(awk -v ver="$version" '
$0 ~ "^##[[:space:]]+" ver "[[:space:]]*$" { in_section=1; next }
in_section && $0 ~ "^##[[:space:]]+" { exit }
in_section { print }
' "$changelog_path" | sed '/./,$!d' || true)

if [[ -z "$section_body" ]]; then
echo "No CHANGELOG entry found for version '${version}' in '${changelog_path}'" >&2
exit 1
fi

printf "%s\n" "$section_body" > "$body_file"

echo "path=$body_file" >> "$GITHUB_OUTPUT"

- name: Create GitHub release
id: release
if: ${{ steps.release_check.outputs.exists != 'true' }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
body_path: ${{ steps.release_body.outputs.path }}
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_GH_TOKEN }}
4 changes: 4 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sync-python-changelog:
cp -f packages/sdk/python/human-protocol-sdk/CHANGELOG.md packages/sdk/python/human-protocol-sdk/docs/CHANGELOG.md
sync-typescript-changelog:
cp -f packages/sdk/typescript/human-protocol-sdk/CHANGELOG.md packages/sdk/typescript/human-protocol-sdk/docs/CHANGELOG.md
6 changes: 4 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

## Deploying a new version (mike)
- TypeScript:
`yarn workspace @human-protocol/sdk build:doc`
`yarn workspace @human-protocol/sdk build:doc`
`make -f ./docs/Makefile sync-typescript-changelog`
`mike deploy -F ./docs/mkdocs-ts.yaml --deploy-prefix docs/ts [VERSION]`
`mike set-default -F ./docs/mkdocs-ts.yaml --deploy-prefix docs/ts [VERSION]`
- Python:
- Python:
`make -f ./docs/Makefile sync-python-changelog`
`mike deploy -F ./docs/mkdocs-python.yaml --deploy-prefix docs/python [VERSION]`
`mike set-default -F ./docs/mkdocs-python.yaml --deploy-prefix docs/python [VERSION]`

Expand Down
1 change: 1 addition & 0 deletions docs/mkdocs-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,6 @@ nav:
- Worker:
- WorkerUtils: worker_utils.md
- Core utilities: core.md
- Changelog: CHANGELOG.md
extra_css:
- assets/css/custom.css
1 change: 1 addition & 0 deletions docs/mkdocs-ts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ nav:
- TransactionUtils: classes/TransactionUtils.md
- Worker:
- WorkerUtils: classes/WorkerUtils.md
- Changelog: CHANGELOG.md
extra_css:
- assets/css/custom.css
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"packages/**"
],
"devDependencies": {
"@changesets/changelog-git": "^0.2.1",
"@changesets/cli": "^2.29.6",
"husky": "^9.1.6",
"lint-staged": "^16.2.7"
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/python/human-protocol-sdk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ contracts

# Hypothesis
.hypothesis

docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,4 @@ def get_cancellation_refund_by_escrow_query():
}}
}}
{cancellation_refund_fragment}
""".format(
cancellation_refund_fragment=cancellation_refund_fragment
)
""".format(cancellation_refund_fragment=cancellation_refund_fragment)
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ def get_escrow_query():
}}
}}
{escrow_fragment}
""".format(
escrow_fragment=escrow_fragment
)
""".format(escrow_fragment=escrow_fragment)


def get_status_query(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@
}}
}}
{reward_added_event_fragment}
""".format(
reward_added_event_fragment=reward_added_event_fragment
)
""".format(reward_added_event_fragment=reward_added_event_fragment)
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,4 @@ def get_transaction_query() -> str:
}}
}}
{transaction_fragment}
""".format(
transaction_fragment=transaction_fragment
)
""".format(transaction_fragment=transaction_fragment)
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def get_worker_query() -> str:
}}
}}
{worker_fragment}
""".format(
worker_fragment=worker_fragment
)
""".format(worker_fragment=worker_fragment)


def get_workers_query(filter: WorkerFilter) -> str:
Expand Down
4 changes: 3 additions & 1 deletion packages/sdk/typescript/human-protocol-sdk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ dist
logs

docs
!docs/index.md
!docs/index.md

docs/CHANGELOG.md
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21079,6 +21079,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "human-protocol@workspace:."
dependencies:
"@changesets/changelog-git": "npm:^0.2.1"
"@changesets/cli": "npm:^2.29.6"
husky: "npm:^9.1.6"
lint-staged: "npm:^16.2.7"
Expand Down
Loading