Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build sea for windows macos and linux #59

Merged
merged 2 commits into from
Jun 18, 2024
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
130 changes: 130 additions & 0 deletions .github/workflows/build-seas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Runtime Tests
on:
workflow_call:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we name this token for what it is so we can find it ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an org token, for making requests to github. It's used in many places/repos
This being a herodevs repo, I don't know anything about it.


jobs:
build-seas:
name: ${{ matrix.os}}
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/setup-node@v4
with:
node-version: '22'

- name: set the executable name
id: set-executable-name
uses: actions/github-script@v7
env:
MATRIX_OS: ${{ matrix.os }}
with:
script: |
const os = process.env.MATRIX_OS;
let executableName = 'hdcli';
if (os === 'windows-latest') {
executableName = 'hdcli.exe';
}
return executableName;
result-encoding: string

- name: restore the sea blob from cache
uses: actions/cache/restore@v4
with:
path: ./dist/apps/cli/sea-prep.blob
key: hdcli-sea-blob-${{ github.run_id }}
enableCrossOsArchive: true

- name: copy node to use to create sea
if: matrix.os != 'windows-latest'
run: cp $(command -v node) hdcli
working-directory: ./dist/apps/cli
shell: bash

- name: copy node to use to create sea
if: matrix.os == 'windows-latest'
run: node -e "require('fs').copyFileSync(process.execPath, 'hdcli.exe')"
working-directory: dist\apps\cli
shell: pwsh

- name: remove the signature of the binary
if: matrix.os == 'macos-latest'
run: codesign --remove-signature hdcli
working-directory: ./dist/apps/cli
shell: bash

- name: inject the CLI sea into the copied node
if: matrix.os == 'ubuntu-latest'
run: npx postject ${{ steps.set-executable-name.outputs.result }} NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
working-directory: ./dist/apps/cli
shell: bash

- name: inject the CLI sea into the copied node
if: matrix.os == 'windows-latest'
run: npx postject ${{ steps.set-executable-name.outputs.result }} NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
working-directory: dist\apps\cli
shell: pwsh

- name: inject the CLI sea into the copied node
if: matrix.os == 'macos-latest'
run: npx postject ${{ steps.set-executable-name.outputs.result }} NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 --macho-segment-name NODE_SEA
working-directory: ./dist/apps/cli
shell: bash

- name: sign the binary
if: matrix.os == 'macos-latest'
run: codesign --sign - ${{ steps.set-executable-name.outputs.result }}
working-directory: ./dist/apps/cli
shell: bash

# would require a certificate to sign the binary on windows
# - name: sign the binary
# if: matrix.os == 'windows-latest'
# run: signtool sign /fd SHA256 ${{ steps.set-executable-name.outputs.result }}
# working-directory: dist\apps\cli
# shell: pwsh

- name: cache the sea binary
uses: actions/cache/save@v4
with:
path: ./dist/apps/cli/${{ steps.set-executable-name.outputs.result }}
key: hdcli-sea-${{ matrix.os }}-${{ github.run_id }}
enableCrossOsArchive: true

- name: set the executable name
id: set-os-nice-name
uses: actions/github-script@v7
env:
MATRIX_OS: ${{ matrix.os }}
with:
script: |
const os = process.env.MATRIX_OS;
let osNiceName = os.replace('-latest', '');
if (os === 'ubuntu-latest') {
osNiceName = 'linux';
}
return osNiceName;
result-encoding: string

- name: zip the sea binary
if: matrix.os != 'windows-latest'
run: zip -r hdcli-${{ steps.set-os-nice-name.outputs.result }}.zip ${{ steps.set-executable-name.outputs.result }}
working-directory: ./dist/apps/cli
shell: bash

- name: zip the sea binary
if: matrix.os == 'windows-latest'
run: Compress-Archive -Path ${{ steps.set-executable-name.outputs.result }} -Destination hdcli-${{ steps.set-os-nice-name.outputs.result }}.zip
working-directory: dist\apps\cli
shell: pwsh

- name: cache the zip
uses: actions/cache/save@v4
with:
key: hdcli-sea-${{ steps.set-os-nice-name.outputs.result }}-zip-${{ github.run_id }}
path: ./dist/apps/cli/hdcli-${{ steps.set-os-nice-name.outputs.result }}.zip
enableCrossOsArchive: true
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jobs:
- uses: actions/checkout@v4
- uses: ./.github/workflows/composite/build

verify:
build-seas:
needs: build
uses: ./.github/workflows/build-seas.yml

verify:
needs: build-seas
uses: ./.github/workflows/runtime-tests.yml
17 changes: 4 additions & 13 deletions .github/workflows/composite/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,9 @@ runs:
working-directory: ./dist/apps/cli
shell: bash

- name: copy node to use to create sea
run: cp $(command -v node) hdcli
working-directory: ./dist/apps/cli
shell: bash

- name: inject the CLI sea into the copied node
run: npx postject hdcli NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
working-directory: ./dist/apps/cli
shell: bash

- name: cache the sea
- name: cache the sea blob
uses: actions/cache/save@v4
with:
path: ./dist/apps/cli/hdcli
key: hdcli-sea-${{ github.run_id }}
path: ./dist/apps/cli/sea-prep.blob
key: hdcli-sea-blob-${{ github.run_id }}
enableCrossOsArchive: true
70 changes: 69 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ jobs:

- uses: ./.github/workflows/composite/build

verify:
build-seas:
needs: build
uses: ./.github/workflows/build-seas.yml

verify:
needs: build-seas
uses: ./.github/workflows/runtime-tests.yml

release:
runs-on: ubuntu-latest
needs: verify
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -47,3 +53,65 @@ jobs:
run: |
npm version "${{ steps.release-version.outputs.result }}" --no-git-tag-version
npm publish

- name: restore the linux zip from cache
uses: actions/cache/save@v4
with:
key: hdcli-sea-linux-latest-zip-${{ github.run_id }}
path: ./dist/apps/cli/hdcli-linux.zip
enableCrossOsArchive: true

- name: restore the macos zip from cache
uses: actions/cache/save@v4
with:
key: hdcli-sea-macos-zip-${{ github.run_id }}
path: ./dist/apps/cli/hdcli-macos.zip
enableCrossOsArchive: true

- name: restore the windows zip from cache
uses: actions/cache/save@v4
with:
key: hdcli-sea-windows-zip-${{ github.run_id }}
path: ./dist/apps/cli/hdcli.exe-windows.zip
enableCrossOsArchive: true

- name: create release
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref_name }}
draft: false
prerelease: false

- name: upload linux zip asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_path: ./dist/apps/cli/hdcli-linux.zip
asset_name: hdcli-linux.zip
asset_content_type: application/zip

- name: upload macos zip asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_path: ./dist/apps/cli/hdcli-macos.zip
asset_name: hdcli-macos.zip
asset_content_type: application/zip

- name: upload windows zip asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question regarding naming

with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_path: ./dist/apps/cli/hdcli-windows.zip
asset_name: hdcli-windows.zip
asset_content_type: application/zip
48 changes: 47 additions & 1 deletion .github/workflows/runtime-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
uses: actions/cache/restore@v4
with:
path: ./dist/apps/cli/hdcli
key: hdcli-sea-${{ github.run_id }}
key: hdcli-sea-ubuntu-latest-${{ github.run_id }}

- name: setup local git repo
run: |
Expand All @@ -77,3 +77,49 @@ jobs:

- name: run the cli
run: ./dist/apps/cli/hdcli report committers

os:
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
name: node ${{ matrix.os }}
runs-on: ${{ matrix.os }}

steps:
- name: set the executable name
id: set-executable-name
uses: actions/github-script@v7
env:
MATRIX_OS: ${{ matrix.os }}
with:
script: |
const os = process.env.MATRIX_OS;
let executableName = 'hdcli';
if (os === 'windows-latest') {
executableName = 'hdcli.exe';
}
return executableName;
result-encoding: string

- name: uncache build output
uses: actions/cache/restore@v4
with:
path: ./dist/apps/cli/${{ steps.set-executable-name.outputs.result }}
key: hdcli-sea-${{ matrix.os }}-${{ github.run_id }}
enableCrossOsArchive: true

- name: setup local git repo
run: |
git config --global user.email "[email protected]"
git config --global user.name "Github CI"
git init
echo "test" > test.txt
git add .
git commit -m "test commit"
echo "test 2" > test.txt
git add .
git commit -m "test commit 2"

- name: run the cli
run: ./dist/apps/cli/${{ steps.set-executable-name.outputs.result }} report committers
6 changes: 4 additions & 2 deletions libs/report/committers/src/lib/committers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { format, subMonths } from 'date-fns';
import { addHours, addMinutes, addSeconds, format, formatISO, subMonths } from 'date-fns';
import { reportCommittersCommand } from './committers';
import { runCommand } from '@herodevs/utility';
import { dateFormat } from './constants';
Expand Down Expand Up @@ -77,8 +77,10 @@ describe('reportCommittersCommand', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
reportCommittersCommand.handler(args as any);

const startDateEndOfDay = formatISO(addHours(addMinutes(addSeconds(startDate, 59), 59), 23));

expect(runCommandMock).toHaveBeenCalledWith(
`git log --since "${endDate}" --until "${startDate}" --pretty=format:"%hΓΓΓΓ%anΓΓΓΓ%ad" `
`git log --since "${endDate}" --until "${startDateEndOfDay}" --pretty=format:"%hΓΓΓΓ%anΓΓΓΓ%ad" `
);
});

Expand Down
8 changes: 6 additions & 2 deletions libs/report/committers/src/lib/committers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { format, subMonths } from 'date-fns';
import { addHours, addMinutes, addSeconds, format, formatISO, subMonths } from 'date-fns';
import { runCommand } from '@herodevs/utility';
import { parseDateFlags } from './parse-date-flags';
import { dateFormat, gitOutputFormat, monthsToSubtract } from './constants';
Expand Down Expand Up @@ -57,8 +57,12 @@ export const reportCommittersCommand: CommandModule<object, Options> = {

async function run(args: ArgumentsCamelCase<Options>): Promise<void> {
const { startDate, endDate } = parseDateFlags(dateFormat, args.startDate, args.endDate);
const startDateEndOfDay = formatISO(addHours(addMinutes(addSeconds(startDate, 59), 59), 23));

const ignores = args.exclude && args.exclude.length ? `-- . "!(${args.exclude.join('|')})"` : '';
const gitCommand = `git log --since "${endDate}" --until "${startDate}" --pretty=format:${gitOutputFormat} ${ignores}`;

const gitCommand = `git log --since "${endDate}" --until "${startDateEndOfDay}" --pretty=format:${gitOutputFormat} ${ignores}`;

const result = await runCommand(gitCommand);

const rawEntries = (result as string).split('\n');
Expand Down