Skip to content

Refresh installer setup flow #194

Refresh installer setup flow

Refresh installer setup flow #194

Workflow file for this run

name: Release
on:
push:
branches: [main]
pull_request:
branches: [main]
types: [opened, reopened, synchronize, ready_for_review]
permissions:
contents: write
actions: read
issues: write
packages: write
pull-requests: write
attestations: write
id-token: write
jobs:
release:
# Skip bot commits (from version bump commits pushed by this workflow)
if: github.event_name == 'push' && github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.tag }}
released: ${{ steps.changesets.outputs.found }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# Check for pending changesets before doing anything expensive
- name: Check for changesets
id: changesets
run: |
if ls .changeset/*.md 2>/dev/null | grep -qv README.md; then
echo "found=true" >> $GITHUB_OUTPUT
else
echo "found=false" >> $GITHUB_OUTPUT
fi
- if: steps.changesets.outputs.found == 'true'
uses: oven-sh/setup-bun@v2
with:
bun-version: "1.2.x"
- if: steps.changesets.outputs.found == 'true'
uses: pnpm/action-setup@v4
- if: steps.changesets.outputs.found == 'true'
uses: actions/setup-node@v4
with:
node-version: "22"
registry-url: "https://registry.npmjs.org"
- if: steps.changesets.outputs.found == 'true'
run: pnpm install --frozen-lockfile
# Version packages (consumes changesets, bumps versions)
- name: Version packages
if: steps.changesets.outputs.found == 'true'
run: pnpm changeset version
# Format files modified by changeset version
- name: Format
if: steps.changesets.outputs.found == 'true'
run: pnpm format
# Build all publishable packages
- name: Build packages
if: steps.changesets.outputs.found == 'true'
run: pnpm -r --filter "@parity/cdm-utils" --filter "@parity/cdm-env" --filter "@parity/cdm-builder" --filter "@parity/cdm-codegen" build
# Commit version bumps
- name: Commit version changes
if: steps.changesets.outputs.found == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git diff --cached --quiet || git commit -m "chore: version packages"
git push
# Create git tags for versioned public packages. The CLI release tag
# is created by the GitHub release step below.
- name: Create and push package tags
if: steps.changesets.outputs.found == 'true'
run: |
for pkg in \
src/lib/utils/package.json \
src/lib/env/package.json \
src/lib/contracts/package.json \
src/lib/cdm/typescript/package.json; do
name=$(jq -r '.name' "$pkg")
version=$(jq -r '.version' "$pkg")
tag="${name}@${version}"
if ! git tag -l "$tag" | grep -q .; then
git tag "$tag"
fi
done
git push --tags
# Pack all public npm packages for npm_publish_automation.
- name: Pack packages
if: steps.changesets.outputs.found == 'true'
run: |
mkdir -p artifacts
for dir in \
src/lib/utils \
src/lib/env \
src/lib/contracts \
src/lib/cdm/typescript; do
(cd "$dir" && pnpm pack --pack-destination "$GITHUB_WORKSPACE/artifacts")
done
- name: Upload package artifacts
if: steps.changesets.outputs.found == 'true'
uses: actions/upload-artifact@v4
with:
name: packages
path: artifacts/*.tgz
- name: Publish via npm_publish_automation
if: steps.changesets.outputs.found == 'true'
uses: octokit/request-action@02f5e7c637a73a3b12ed81015fa7fb5f11cc5d7d # v2.x
with:
route: POST /repos/paritytech/npm_publish_automation/actions/workflows/publish.yml/dispatches
ref: main
inputs: '${{ format(''{{ "repo": "{0}", "run_id": "{1}", "artifact_name": "packages" }}'', github.repository, github.run_id) }}'
env:
GITHUB_TOKEN: ${{ secrets.NPM_PUBLISH_AUTOMATION_TOKEN }}
# Compile CLI binaries
- name: Compile binaries
if: steps.changesets.outputs.found == 'true'
run: |
make embed-templates
bun build --compile --target=bun-linux-x64 src/apps/cli/src/cli.ts --outfile cdm-linux-x64
bun build --compile --target=bun-linux-arm64 src/apps/cli/src/cli.ts --outfile cdm-linux-arm64
bun build --compile --target=bun-darwin-x64 src/apps/cli/src/cli.ts --outfile cdm-darwin-x64
bun build --compile --target=bun-darwin-arm64 src/apps/cli/src/cli.ts --outfile cdm-darwin-arm64
# Create GitHub Release with binaries
- name: Generate release tag
if: steps.changesets.outputs.found == 'true'
id: tag
run: |
# Use the @parity/cdm-cli version as the release tag
VERSION=$(node -p "require('./src/apps/cli/package.json').version")
TAG="v${VERSION}"
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create Release
if: steps.changesets.outputs.found == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.tag.outputs.tag }}
name: Release ${{ steps.tag.outputs.tag }}
files: |
cdm-linux-x64
cdm-linux-arm64
cdm-darwin-x64
cdm-darwin-arm64
generate_release_notes: true
dev-cli-release:
if: github.event_name == 'pull_request' && !github.event.pull_request.draft && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
concurrency:
group: dev-cli-release-pr-${{ github.event.pull_request.number }}
cancel-in-progress: true
env:
DEV_TAG: cdm-cli-dev-pr-${{ github.event.pull_request.number }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Check for CLI changeset
id: cli_changeset
run: |
found=false
files=$(git diff --name-only \
"${{ github.event.pull_request.base.sha }}" \
"${{ github.event.pull_request.head.sha }}" \
-- '.changeset/*.md' || true)
while IFS= read -r file; do
[ -n "$file" ] || continue
if [ -f "$file" ] && grep -Eq '^"@parity/cdm-cli":[[:space:]]*(patch|minor|major)' "$file"; then
found=true
break
fi
done <<< "$files"
echo "found=$found" >> "$GITHUB_OUTPUT"
echo "CLI changeset: $found"
- if: steps.cli_changeset.outputs.found == 'true'
uses: oven-sh/setup-bun@v2
with:
bun-version: "1.2.x"
- if: steps.cli_changeset.outputs.found == 'true'
uses: pnpm/action-setup@v4
- if: steps.cli_changeset.outputs.found == 'true'
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Build dev CLI binaries
if: steps.cli_changeset.outputs.found == 'true'
run: |
pnpm install --frozen-lockfile
pnpm -r --filter "@parity/cdm-utils" --filter "@parity/cdm-env" --filter "@parity/cdm-builder" --filter "@parity/cdm-codegen" build
make embed-templates
for target in linux-x64 linux-arm64 darwin-x64 darwin-arm64; do
bun build --compile --target="bun-$target" src/apps/cli/src/cli.ts --outfile "cdm-$target"
done
- name: Publish or remove dev release
env:
GH_TOKEN: ${{ github.token }}
FOUND: ${{ steps.cli_changeset.outputs.found }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR: ${{ github.event.pull_request.number }}
run: |
gh release delete "$DEV_TAG" --yes --cleanup-tag || true
git push origin ":refs/tags/$DEV_TAG" >/dev/null 2>&1 || true
[ "$FOUND" = "true" ] || exit 0
gh release create "$DEV_TAG" \
cdm-linux-x64 cdm-linux-arm64 cdm-darwin-x64 cdm-darwin-arm64 \
--target "$HEAD_SHA" \
--title "CDM CLI dev release for PR #$PR" \
--notes "Dev CLI binary for PR #$PR at $HEAD_SHA." \
--prerelease
- name: Sync PR comment
uses: actions/github-script@v7
env:
FOUND: ${{ steps.cli_changeset.outputs.found }}
DEV_TAG: ${{ env.DEV_TAG }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
with:
script: |
const marker = "<!-- cdm-cli-dev-release -->";
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const comments = await github.paginate(github.rest.issues.listComments, {
owner, repo, issue_number,
});
const existing = comments.find(
(c) => c.user?.type === "Bot" && c.body?.includes(marker),
);
if (process.env.FOUND !== "true") {
if (existing) {
await github.rest.issues.deleteComment({ owner, repo, comment_id: existing.id });
}
return;
}
const tag = process.env.DEV_TAG;
const sha = process.env.HEAD_SHA;
const body = [
marker,
"### CDM CLI dev release",
"",
"This PR includes a `@parity/cdm-cli` changeset, so CI published a dev CLI release for this branch.",
"",
"Install it:",
"",
"```sh",
`curl -fsSL https://raw.githubusercontent.com/${owner}/${repo}/${sha}/install.sh | CDM_TAG=${tag} bash`,
"```",
"",
"Update an existing install:",
"",
"```sh",
`cdm update --tag ${tag}`,
"```",
"",
`Release tag: \`${tag}\``,
`Commit: \`${sha}\``,
].join("\n");
if (existing) {
await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body });
} else {
await github.rest.issues.createComment({ owner, repo, issue_number, body });
}
docker:
needs: release
if: needs.release.outputs.released == 'true'
uses: ./.github/workflows/docker.yml
with:
tag: ${{ needs.release.outputs.tag }}