-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from CloudCannon/feat/windows
Windows binary release
- Loading branch information
Showing
5 changed files
with
273 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
const version = process.env.GIT_VERSION; | ||
const changelogFile = path.join(__dirname, "../CHANGELOG.md"); | ||
const releaseFile = path.join(__dirname, "../RELEASE.md"); | ||
|
||
const err = (m) => { | ||
console.error(m); | ||
process.exit(1); | ||
} | ||
|
||
const date = () => { | ||
let options = { year: 'numeric', month: 'long', day: 'numeric' }; | ||
return new Date().toLocaleString('en-US', options); | ||
} | ||
|
||
if (!version) err("Script expected a GIT_VERSION environment variable"); | ||
|
||
if (!fs.existsSync(changelogFile)) err(`Script expected a file at ${changelogFile}`); | ||
|
||
let contents = fs.readFileSync(changelogFile, { encoding: "utf-8" }); | ||
let release = [], lines = contents.split(/\n/g); | ||
let it = lines.entries(); | ||
|
||
while (!(entry = it.next()).done) { | ||
let [num, line] = entry.value; | ||
// Read until we reach our unreleased changelog section. | ||
if (/^\s*## Unreleased\s*$/.test(line)) { | ||
let header = `## ${version} (${date()})`; | ||
lines[num] = `## Unreleased\n\n${header}`; | ||
release.push(header); | ||
break; | ||
} | ||
} | ||
|
||
|
||
while (!(entry = it.next()).done) { | ||
let [, line] = entry.value; | ||
// Read until we reach the section for a new version. | ||
if (/^\s*##\s+v/i.test(line)) { | ||
break; | ||
} | ||
release.push(line); | ||
} | ||
|
||
if (!release.some((v => v.trim().length))) { | ||
err([ | ||
`No unreleased changes exist in ${changelogFile}.`, | ||
`Cancelling release — please write release notes!` | ||
].join('\n')); | ||
} | ||
|
||
if (process.argv[2] === "write") { | ||
fs.writeFileSync(releaseFile, release.join('\n')); | ||
fs.writeFileSync(changelogFile, lines.join('\n')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
const version = process.env.GIT_VERSION; | ||
const version_re = /version\s*[=:]\s*"0.0.0"/; | ||
|
||
const err = (m) => { | ||
console.error(m); | ||
process.exit(1); | ||
} | ||
|
||
if (!version) err("Script expected a GIT_VERSION environment variable"); | ||
|
||
const file = (localPath) => { | ||
localPath = localPath.join(__dirname, "../humane/Cargo.toml"); | ||
if (!fs.existsSync(localPath)) err(`Script expected a file at ${localPath}`); | ||
const contents = fs.readFileSync(localPath, { encoding: "utf-8" }); | ||
if (!version_re.test(contents)) err(`Expected ${localPath} to contain a version of "0.0.0"`); | ||
return { path: localPath, contents }; | ||
} | ||
|
||
let pagefindCfg = file("../pagefind/Cargo.toml"); | ||
pagefindCfg.contents = pagefindCfg.contents.replace(version_re, `version = "${version}"`); | ||
fs.writeFileSync(pagefindCfg.path, pagefindCfg.contents); | ||
|
||
let pagefindWebCfg = file("../pagefind_web/Cargo.toml"); | ||
pagefindWebCfg.contents = pagefindWebCfg.contents.replace(version_re, `version = "${version}"`); | ||
fs.writeFileSync(pagefindWebCfg.path, pagefindWebCfg.contents); | ||
|
||
let pagefindUiCfg = file("../pagefind_ui/package.json"); | ||
pagefindUiCfg.contents = pagefindUiCfg.contents.replace(version_re, `version: "${version}"`); | ||
fs.writeFileSync(pagefindUiCfg.path, pagefindUiCfg.contents); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,13 @@ on: | |
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
HUMANE_VERSION: "0.3.4" | ||
|
||
jobs: | ||
publish-crate: | ||
name: Publish Crate | ||
runs-on: ubuntu-20.04 | ||
needs: publish-to-github | ||
needs: publish-github-release | ||
steps: | ||
- name: Clone | ||
uses: actions/checkout@v2 | ||
|
@@ -46,9 +47,7 @@ jobs: | |
- name: Prepare Crates | ||
run: | | ||
# Update cargo version, | ||
printf ",s/version = \"0.0.0\"/version = \"$GIT_VERSION\"/g\nw\n" | ed ./pagefind/Cargo.toml | ||
printf ",s/version = \"0.0.0\"/version = \"$GIT_VERSION\"/g\nw\n" | ed ./pagefind_web/Cargo.toml | ||
printf ",s/\"version\": \"0.0.0\"/\"version\": \"$GIT_VERSION\"/g\nw\n" | ed ./pagefind_ui/package.json | ||
node ./.backstage/version.cjs | ||
git add ./pagefind/Cargo.toml | ||
git add ./pagefind_web/Cargo.toml | ||
git add ./pagefind_ui/package.json | ||
|
@@ -80,29 +79,65 @@ jobs: | |
publish-npm-package: | ||
name: Publish NPM package | ||
runs-on: ubuntu-20.04 | ||
needs: publish-to-github | ||
needs: publish-github-release | ||
defaults: | ||
run: | ||
working-directory: ./wrappers/node | ||
steps: | ||
- name: Clone | ||
uses: actions/checkout@v2 | ||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: release-checksums | ||
path: wrappers/node/checksums | ||
- name: Prepare package | ||
run: | | ||
RELEASE_VERSION=${GITHUB_REF#refs/tags/} | ||
npm version $(echo $RELEASE_VERSION | cut -c1-) | ||
mkdir checksums | ||
for TARGET in x86_64-unknown-linux-musl x86_64-apple-darwin | ||
do | ||
ASSET_NAME="pagefind-$RELEASE_VERSION-$TARGET.tar.gz.sha256" | ||
curl -L https://github.com/CloudCannon/pagefind/releases/download/$RELEASE_VERSION/$ASSET_NAME -o checksums/$ASSET_NAME | ||
done | ||
- name: Publish | ||
run: npm publish | ||
env: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
||
publish-to-github: | ||
publish-github-release: | ||
name: Publish to GitHub | ||
runs-on: ubuntu-20.04 | ||
needs: test-and-build | ||
defaults: | ||
run: | ||
working-directory: ./ | ||
steps: | ||
- name: Clone | ||
uses: actions/checkout@v2 | ||
- name: Get Version | ||
run: echo GIT_VERSION="$(git describe --tags | sed 's/^v\(.*\)$/\1/')" >> $GITHUB_ENV | ||
- name: Swap to main | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: main | ||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: release | ||
path: build-artifacts | ||
- name: Build Changelog | ||
run: | | ||
node ./.backstage/changelog.cjs write | ||
git config user.email "github-actions[bot]@users.noreply.github.com" | ||
git config user.name "github-actions[bot]" | ||
git add ./CHANGELOG.md | ||
git commit -m "Changelog for $GIT_VERSION" | ||
git push | ||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
if: startsWith(github.ref, 'refs/tags/') | ||
with: | ||
body_path: RELEASE.md | ||
files: | | ||
build-artifacts/* | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
test-and-build: | ||
name: Publish to Github and Crates | ||
runs-on: ${{matrix.os}} | ||
defaults: | ||
|
@@ -111,6 +146,12 @@ jobs: | |
strategy: | ||
matrix: | ||
include: | ||
- build: windows | ||
os: windows-latest | ||
rust: stable | ||
target: x86_64-pc-windows-msvc | ||
cross: false | ||
musl: false | ||
- build: linux | ||
os: ubuntu-latest | ||
rust: stable | ||
|
@@ -139,6 +180,18 @@ jobs: | |
target | ||
key: ${{ runner.os }}-${{ matrix.rust }} | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
|
||
# From https://github.com/Emoun/duplicate/blob/master/.github/workflows/rust.yml | ||
- name: Get Version | ||
run: echo GIT_VERSION="$(git describe --tags | sed 's/^v\(.*\)$/\1/')" >> $GITHUB_ENV | ||
|
||
- name: Verify Changelog | ||
run: | | ||
node ./.backstage/changelog.cjs | ||
- name: Install Linker | ||
if: matrix.cross | ||
run: | | ||
|
@@ -162,16 +215,12 @@ jobs: | |
uses: browser-actions/setup-chrome@latest | ||
|
||
- name: Install humane | ||
uses: XAMPPRocky/get-github-release@v1 | ||
uses: supplypike/setup-bin@v1 | ||
with: | ||
matches: ${{matrix.target}} | ||
owner: cloudcannon | ||
repo: humane | ||
token: "${{ secrets.GITHUB_TOKEN }}" | ||
uri: "https://github.com/CloudCannon/humane/releases/download/v${{env.HUMANE_VERSION}}/humane-v${{env.HUMANE_VERSION}}-${{matrix.target}}.tar.gz" | ||
name: "humane" | ||
version: ${{env.HUMANE_VERSION}} | ||
|
||
# From https://github.com/Emoun/duplicate/blob/master/.github/workflows/rust.yml | ||
- name: Get Version | ||
run: echo GIT_VERSION="$(git describe --tags | sed 's/^v\(.*\)$/\1/')" >> $GITHUB_ENV | ||
- name: Prepare Git | ||
run: | | ||
git config user.email "[email protected]" | ||
|
@@ -182,9 +231,7 @@ jobs: | |
- name: Prepare Crates | ||
run: | | ||
# Update cargo version, | ||
printf ",s/version = \"0.0.0\"/version = \"$GIT_VERSION\"/g\nw\n" | ed ./pagefind/Cargo.toml | ||
printf ",s/version = \"0.0.0\"/version = \"$GIT_VERSION\"/g\nw\n" | ed ./pagefind_web/Cargo.toml | ||
printf ",s/\"version\": \"0.0.0\"/\"version\": \"$GIT_VERSION\"/g\nw\n" | ed ./pagefind_ui/package.json | ||
node ./.backstage/version.cjs | ||
git add ./pagefind/Cargo.toml | ||
git add ./pagefind_web/Cargo.toml | ||
git add ./pagefind_ui/package.json | ||
|
@@ -209,21 +256,17 @@ jobs: | |
working-directory: ./pagefind_web | ||
run: cargo test --release | ||
|
||
- name: Build Testing Binary | ||
- name: Build | ||
working-directory: ./pagefind | ||
run: cargo build --release | ||
run: cargo build --release --target ${{ matrix.target }} | ||
|
||
- name: Test Lib | ||
working-directory: ./pagefind | ||
run: cargo test --release | ||
run: cargo test --release --target ${{ matrix.target }} | ||
|
||
- name: Test CLI | ||
working-directory: ./pagefind | ||
run: TEST_BINARY=../target/release/pagefind /tmp/humane | ||
|
||
- name: Build | ||
working-directory: ./pagefind | ||
run: RELEASE_VERSION=${GITHUB_REF#refs/tags/} cargo build --release --target ${{ matrix.target }} | ||
run: TEST_BINARY=../target/${{ matrix.target }}/release/pagefind humane | ||
|
||
- name: Package Artifacts | ||
run: | | ||
|
@@ -265,12 +308,16 @@ jobs: | |
fi | ||
echo "ASSET_PATH=$ASSET_PATH" >> $GITHUB_ENV | ||
echo "CHECKSUM_PATH=$CHECKSUM_PATH" >> $GITHUB_ENV | ||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
if: startsWith(github.ref, 'refs/tags/') | ||
- name: Upload build artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
files: | | ||
name: release | ||
path: | | ||
${{ env.ASSET_PATH }} | ||
${{ env.CHECKSUM_PATH }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Upload build artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: release-checksums | ||
path: | | ||
${{ env.CHECKSUM_PATH }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.