Skip to content

Commit

Permalink
final fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
YassinEldeeb committed Jul 29, 2024
1 parent b89fbf8 commit 449b10d
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 95 deletions.
5 changes: 0 additions & 5 deletions .changeset/@graphprotocol_graph-cli-1549-dependencies.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/slow-pears-agree.md

This file was deleted.

82 changes: 41 additions & 41 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,44 +279,44 @@ jobs:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

# CLI
# stable:
# name: Stable
# runs-on: ubuntu-latest
# needs: publish-napi-utils
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# with:
# fetch-depth: 0
# token: ${{ secrets.GITHUB_TOKEN }}
# - name: Setup environment
# uses: the-guild-org/shared-config/setup@main
# with:
# nodeVersion: 20
# packageManager: pnpm
# packageManagerVersion: 9.1.0

# - name: Set variables
# id: vars
# run: |
# echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
# echo "date=$(date +"%B %d, %Y")" >> $GITHUB_OUTPUT
# - name: Build
# if: ${{ startsWith(github.event.head_commit.message, env.RELEASE_COMMIT_MSG) }}
# run: pnpm --filter=@graphprotocol/graph-cli build
# - name: Pack binaries
# if: ${{ startsWith(github.event.head_commit.message, env.RELEASE_COMMIT_MSG) }}
# run: pnpm --filter=@graphprotocol/graph-cli oclif:pack
# - name: Release / pull_request
# uses: dotansimha/[email protected]
# with:
# publish: pnpm release
# version: pnpm changeset version
# commit: ${{ env.RELEASE_COMMIT_MSG }}
# title: Upcoming Release Changes
# createGithubReleases: true
# githubReleaseName: ${{ steps.vars.outputs.date }}
# githubReleaseAssets: packages/cli/dist/*.tar.gz
# env:
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
stable:
name: Stable
runs-on: ubuntu-latest
needs: publish-napi-utils
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup environment
uses: the-guild-org/shared-config/setup@main
with:
nodeVersion: 20
packageManager: pnpm
packageManagerVersion: 9.1.0

- name: Set variables
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "date=$(date +"%B %d, %Y")" >> $GITHUB_OUTPUT
- name: Build
if: ${{ startsWith(github.event.head_commit.message, env.RELEASE_COMMIT_MSG) }}
run: pnpm --filter=@graphprotocol/graph-cli build
- name: Pack binaries
if: ${{ startsWith(github.event.head_commit.message, env.RELEASE_COMMIT_MSG) }}
run: pnpm --filter=@graphprotocol/graph-cli oclif:pack
- name: Release / pull_request
uses: dotansimha/[email protected]
with:
publish: pnpm release
version: pnpm changeset version
commit: ${{ env.RELEASE_COMMIT_MSG }}
title: Upcoming Release Changes
createGithubReleases: true
githubReleaseName: ${{ steps.vars.outputs.date }}
githubReleaseAssets: packages/cli/dist/*.tar.gz
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@float-capital/float-subgraph-uncrashable": "^0.0.0-alpha.4",
"@graphprotocol/graph-tooling-napi-utils": "workspace:*",
"@graphprotocol/graph-tooling-napi-utils": "0.1.0",
"@oclif/core": "2.8.6",
"@oclif/plugin-autocomplete": "^2.3.6",
"@oclif/plugin-not-found": "^2.4.0",
Expand Down
80 changes: 40 additions & 40 deletions packages/cli/src/commands/test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { execSync } from 'child_process';
import path from 'path';
import { filesystem } from 'gluegun';
import yaml from 'js-yaml';
import { execSync } from 'child_process'
import path from 'path'
import { filesystem } from 'gluegun'
import yaml from 'js-yaml'
// This'd import the N-API bindings based on the OS and architecture
import { Args, Command, Flags } from '@oclif/core';
import { Args, Command, Flags } from '@oclif/core'

export default class TestCommand extends Command {
static description = 'Runs rust binary for subgraph testing.';
Expand Down Expand Up @@ -44,53 +44,53 @@ export default class TestCommand extends Command {
const {
args: { datasource },
flags: { coverage, force, logs, recompile, version },
} = await this.parse(TestCommand);
} = await this.parse(TestCommand)

// Ensure PostgreSQL 14 is installed
// Ensure PostgreSQL 16 is installed
try {
const versionOutput = execSync('psql --version').toString();
const versionMatch = versionOutput.match(/\b14\.\d+/);
const versionOutput = execSync('psql --version').toString()
const versionMatch = versionOutput.match(/\b(14|15|16)\.\d+/)
if (!versionMatch) {
this.error(`PostgreSQL version 14 is required. Detected version: ${versionOutput}`, {
this.error(`PostgreSQL version >=14 is required. Detected version: ${versionOutput}`, {
exit: 1,
});
})
}
} catch (error) {
this.error(
`PostgreSQL version 14 is required. It seems PostgreSQL is not installed.\n
To install PostgreSQL 14:\n
`PostgreSQL version >=14 is required. It seems PostgreSQL is not installed.\n
To install PostgreSQL 16:\n
On Linux (Ubuntu/Debian based):
sudo apt update
sudo apt install -y postgresql-14
sudo apt install -y postgresql-16
On macOS:
brew install postgresql@14`,
brew install postgresql@16`,
{
exit: 1,
},
);
)
}

let testsDir = './tests';
let testsDir = './tests'

// Check if matchstick.yaml config exists
if (filesystem.exists('matchstick.yaml')) {
try {
// Load the config
const config = await yaml.load(filesystem.read('matchstick.yaml', 'utf8')!);
const config = await yaml.load(filesystem.read('matchstick.yaml', 'utf8')!)
// Check if matchstick.yaml and testsFolder not null
if (config?.testsFolder) {
// assign test folder from matchstick.yaml if present
testsDir = config.testsFolder;
testsDir = config.testsFolder
}
} catch (error) {
this.error(`A problem occurred while reading "matchstick.yaml":\n${error.message}`, {
exit: 1,
});
})
}
}

const cachePath = path.resolve(testsDir, '.latest.json');
const cachePath = path.resolve(testsDir, '.latest.json')
const opts = {
testsDir,
cachePath,
Expand All @@ -100,51 +100,51 @@ export default class TestCommand extends Command {
recompile,
version,
latestVersion: getLatestVersionFromCache(cachePath),
};
}

runNapi.bind(this)(datasource, opts);
runNapi.bind(this)(datasource, opts)
}
}

function getLatestVersionFromCache(cachePath: string) {
if (filesystem.exists(cachePath) == 'file') {
const cached = filesystem.read(cachePath, 'json');
const cached = filesystem.read(cachePath, 'json')
// Get the cache age in days
const cacheAge = (Date.now() - cached.timestamp) / (1000 * 60 * 60 * 24);
const cacheAge = (Date.now() - cached.timestamp) / (1000 * 60 * 60 * 24)
// If cache age is less than 1 day, use the cached version
if (cacheAge < 1) {
return cached.version as string;
return cached.version as string
}
}
return null;
return null
}

async function runNapi(
this: TestCommand,
datasource: string | undefined,
opts: {
coverage: boolean;
force: boolean;
logs: boolean;
version: string | undefined;
latestVersion: string | null;
recompile: boolean;
coverage: boolean
force: boolean
logs: boolean
version: string | undefined
latestVersion: string | null
recompile: boolean
},
) {
const args = [];
const args = []

if (opts.coverage) args.push('--coverage');
if (opts.recompile) args.push('--recompile');
if (datasource) args.push(datasource);
if (opts.coverage) args.push('--coverage')
if (opts.recompile) args.push('--recompile')
if (datasource) args.push(datasource)

try {
// Dynamically import runTests only after PostgreSQL check
const { runTests } = await import('@graphprotocol/graph-tooling-napi-utils/mod/testing');
const { runTests } = await import('@graphprotocol/graph-tooling-napi-utils/mod/testing')
// Call the N-API function
runTests(args);
runTests(args)
} catch (error) {
this.error(`Error running tests:\n${error.message}`, {
exit: 1,
});
})
}
}
2 changes: 1 addition & 1 deletion packages/napi-utils/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/napi-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "matchstick"
name = "napi-utils"
version = "0.6.0"
authors = ["The Graph core developers & contributors"]
edition = "2021"

[lib]
name = "matchstick"
name = "napi-utils"
path = "src/lib.rs"
crate-type = ["cdylib"]

Expand Down

0 comments on commit 449b10d

Please sign in to comment.