Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Test/version updater #85

Merged
merged 8 commits into from
Oct 14, 2022
Merged
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
54 changes: 54 additions & 0 deletions .github/workflows/update-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Update Version

on:
pull_request:
branches:
- development
types: [closed]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: "18"
- uses: pnpm/action-setup@v2.2.2
with:
version: 7.11.0
- name: Install dependencies
run: pnpm install
- name: Update version
run: echo "::set-output name=version::$(node update-beta-version.mjs)"
id: update-version
- name: Build CLI
run: pnpm run build --filter ultrapkg
- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
publish: pnpm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish release
uses: ncipollo/release-action@v1
with:
body: "This release was created by the GitHub Release Action."
name: ${{ steps.update-version.outputs.version }}
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: "packages/cli/build/**, packages/cli/package.json, packages/cli/readme.md"
prerelease: true
tag: ${{ steps.update-version.outputs.version }}
target: "development"
- name: Create comment
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.number }}
body: |
Published alpha release:
- Version: ${{ steps.update-version.outputs.version }}
- NPM URL: https://www.npmjs.com/package/@ultra-cli/cli/v/${{ steps.update-version.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"dev": "turbo run dev --parallel",
"lint": "turbo run lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"publish-pkg": "turbo run publish-pkg",
"changeset": "changeset",
"version-packages": "changeset version",
"release": "turbo run build --filter=apps^... --filter=examples && changeset publish"
Expand All @@ -35,4 +34,4 @@
"node": ">=14.0.0"
},
"packageManager": "pnpm@7.11.0"
}
}
5 changes: 2 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"type": "module",
"scripts": {
"dev": "swc ./src -d ./build --watch",
"build": "swc ./src -d ./build",
"publish-pkg": "pnpm run build && npm publish"
"build": "swc ./src -d ./build"
},
"files": [
"build"
Expand Down Expand Up @@ -51,4 +50,4 @@
"@types/tar": "6.1.3",
"chokidar": "3.5.3"
}
}
}
50 changes: 50 additions & 0 deletions update-beta-version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { readFile, writeFile, readdir, stat } from "node:fs/promises";
import { createHash } from "node:crypto";
import path from "node:path";

async function computeMetaHash(folder, inputHash = null) {
const hash = inputHash ? inputHash : createHash("sha256");
const info = await readdir(folder, { withFileTypes: true });
// construct a string from the modification date, the filename and the filesize
for (let item of info) {
const fullPath = path.join(folder, item.name);
if (item.isFile()) {
const statInfo = await stat(fullPath);
// compute hash string name:size:mtime
const fileInfo = `${fullPath}:${statInfo.size}:${statInfo.mtimeMs}`;
hash.update(fileInfo);
} else if (item.isDirectory()) {
// recursively walk sub-folders
await computeMetaHash(fullPath, hash);
}
}
// if not being called recursively, get the digest and return it as the hash result
if (!inputHash) {
return hash.digest();
}
}

async function updateVersion() {
const packageJson = JSON.parse(
await readFile(
path.join(process.cwd(), "packages", "cli", "package.json"),
"utf8"
)
);
const hash = await computeMetaHash(
path.join(process.cwd(), "packages", "cli", "src")
);
// Convert the hash to a hex string
const hashString = hash.toString("hex");
// Update the version
packageJson.version = `${packageJson.version}-next-${hashString}`;

console.log(`${packageJson.version}`);

await writeFile(
path.join(process.cwd(), "packages", "cli", "package.json"),
JSON.stringify(packageJson, null, 2)
);
}

updateVersion();