Skip to content

Commit

Permalink
Merge branch 'main' into ss/no-multiv
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 authored Jul 30, 2024
2 parents 75a99ec + ad22df3 commit 5788c28
Show file tree
Hide file tree
Showing 22 changed files with 4,559 additions and 214 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ jobs:
exit 1
fi
# This is a meta job to mark successful completion of the required checks,
# even if they are skipped due to no changes in the relevant files.
required-checks:
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/ci-rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ jobs:
run: cargo test --verbose --workspace --all-features --no-run
- name: Tests with all features
run: cargo test --verbose --workspace --all-features
- name: Build HUGR binary
run: cargo build -p hugr-cli
- name: Upload the binary to the artifacts
uses: actions/upload-artifact@v4
with:
name: hugr_binary
path: target/debug/hugr

# Run tests on other toolchains
tests-other:
Expand Down Expand Up @@ -145,6 +152,32 @@ jobs:
- name: Tests with all features
run: cargo test --verbose --workspace --all-features

# Ensure that serialized extensions match rust implementation
std-extensions:
needs: [changes, tests-stable-all-features]
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }}
name: Check standard extensions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download the hugr binary
uses: actions/download-artifact@v4
with:
name: hugr_binary
path: ${{ github.workspace }}/target/debug
- name: Generate the updated definitions
run: |
chmod +x target/debug/hugr
./target/debug/hugr gen-extensions -o specification/std_extensions
- name: Check if the declarations are up to date
run: |
git diff --exit-code --name-only specification/std_extensions/
if [ $? -ne 0 ]; then
echo "The serialized standard extensions are not up to date"
echo "Please run 'just gen-extensions' and commit the changes"
exit 1
fi
tests-nightly-coverage:
needs: changes
# Run only if there are changes in the relevant files
Expand Down
28 changes: 2 additions & 26 deletions .github/workflows/drop-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,5 @@ on:
- closed

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Cleanup
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
drop-cache:
uses: CQCL/hugrverse-actions/.github/workflows/drop-cache.yml@main
153 changes: 5 additions & 148 deletions .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: Check Conventional Commits format

on:
pull_request_target:
branches:
Expand All @@ -13,151 +12,9 @@ on:
merge_group:
types: [checks_requested]

permissions:
pull-requests: write

jobs:
main:
name: Validate Conventional Commit PR title
runs-on: ubuntu-latest
# The action does not support running on merge_group events,
# but if the check succeeds in the PR there is no need to check it again.
if: github.event_name == 'pull_request_target'
outputs:
# Whether the PR title indicates a breaking change.
breaking: ${{ steps.breaking.outputs.breaking }}
# Whether the PR body contains a "BREAKING CHANGE:" footer describing the breaking change.
has_breaking_footer: ${{ steps.breaking.outputs.has_breaking_footer }}
steps:
- name: Validate the PR title format
uses: amannn/action-semantic-pull-request@v5
id: lint_pr_title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Configure which types are allowed (newline-delimited).
# Default: https://github.com/commitizen/conventional-commit-types
types: |
feat
fix
docs
style
refactor
perf
test
ci
chore
revert
# Configure which scopes are allowed (newline-delimited).
# These are regex patterns auto-wrapped in `^ $`.
#scopes: |
# .*
# Configure that a scope must always be provided.
requireScope: false
# Configure which scopes are disallowed in PR titles (newline-delimited).
# For instance by setting the value below, `chore(release): ...` (lowercase)
# and `ci(e2e,release): ...` (unknown scope) will be rejected.
# These are regex patterns auto-wrapped in `^ $`.
#disallowScopes: |
# release
# [A-Z]+
# Configure additional validation for the subject based on a regex.
# This example ensures the subject doesn't start with an uppercase character.
#subjectPattern: ^(?![A-Z]).+$
# If `subjectPattern` is configured, you can use this property to override
# the default error message that is shown when the pattern doesn't match.
# The variables `subject` and `title` can be used within the message.
#subjectPatternError: |
# The subject "{subject}" found in the pull request title "{title}"
# didn't match the configured pattern. Please ensure that the subject
# doesn't start with an uppercase character.
# If the PR contains one of these newline-delimited labels, the
# validation is skipped. If you want to rerun the validation when
# labels change, you might want to use the `labeled` and `unlabeled`
# event triggers in your workflow.
ignoreLabels: |
ignore-semantic-pull-request
# `action-semantic-pull-request` does not parse the title, so it cannot
# detect if it is marked as a breaking change.
#
# Since at this point we know the PR title is a valid conventional commit,
# we can use a simple regex that looks for a '!:' sequence. It could be
# more complex, but we don't care about false positives.
- name: Check for breaking change flag
id: breaking
run: |
if [[ "${PR_TITLE}" =~ ^.*\!:.*$ ]]; then
echo "breaking=true" >> $GITHUB_OUTPUT
else
echo "breaking=false" >> $GITHUB_OUTPUT
fi
# Check if the PR comment has a "BREAKING CHANGE:" footer describing
# the breaking change.
if [[ "${PR_BODY}" != *"BREAKING CHANGE:"* ]]; then
echo "has_breaking_footer=false" >> $GITHUB_OUTPUT
else
echo "has_breaking_footer=true" >> $GITHUB_OUTPUT
fi
env:
PR_TITLE: ${{ github.event.pull_request.title }}
PR_BODY: ${{ github.event.pull_request.body }}

# Post a help comment if the PR title indicates a breaking change but does
# not contain a "BREAKING CHANGE:" footer.
- name: Require "BREAKING CHANGE:" footer for breaking changes
id: breaking-comment
if: ${{ steps.breaking.outputs.breaking == 'true' && steps.breaking.outputs.has_breaking_footer == 'false' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-title-lint-error
message: |
Hey there and thank you for opening this pull request! 👋🏼
It looks like your proposed title indicates a breaking change. If that's the case,
please make sure to include a "BREAKING CHANGE:" footer in the body of the pull request
describing the breaking change and any migration instructions.
GITHUB_TOKEN: ${{ secrets.HUGRBOT_PAT }}
- name: Fail if the footer is required but missing
if: ${{ steps.breaking.outputs.breaking == 'true' && steps.breaking.outputs.has_breaking_footer == 'false' }}
run: exit 1

- name: Post a comment if the PR badly formatted
uses: marocchino/sticky-pull-request-comment@v2
# When the previous steps fails, the workflow would stop. By adding this
# condition you can continue the execution with the populated error message.
if: always() && (steps.lint_pr_title.outputs.error_message != null)
with:
header: pr-title-lint-error
message: |
Hey there and thank you for opening this pull request! 👋🏼
We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/)
and it looks like your proposed title needs to be adjusted.
Your title should look like this. The scope field is optional.
```
<type>(<scope>): <description>
```
If the PR includes a breaking change, mark it with an exclamation mark:
```
<type>!: <description>
```
and include a "BREAKING CHANGE:" footer in the body of the pull request.
Details:
```
${{ steps.lint_pr_title.outputs.error_message }}
```
GITHUB_TOKEN: ${{ secrets.HUGRBOT_PAT }}

# Delete previous comments when the issues have been resolved
# This step doesn't run if any of the previous checks fails.
- name: Delete previous comments
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-title-lint-error
delete: true
GITHUB_TOKEN: ${{ secrets.HUGRBOT_PAT }}
check-title:
name: check-title
uses: CQCL/hugrverse-actions/.github/workflows/pr-title.yml@main
secrets:
GITHUB_PAT: ${{ secrets.HUGRBOT_PAT }}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ lcov.info
__pycache__/
*.py[cod]
*$py.class
*.egg-info

# Unit test / coverage reports
htmlcov/
Expand All @@ -44,6 +45,5 @@ venv/
# ruff
.ruff_cache


# MacOS
*.DS_Store
*.egg-info
24 changes: 12 additions & 12 deletions devenv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1720853497,
"lastModified": 1722262342,
"owner": "cachix",
"repo": "devenv",
"rev": "7f569a0f2473b9f6000fd9e4c32511fd1b0d37c1",
"treeHash": "4d452ecc8223834e39d507f9ea92308f007ee05d",
"rev": "11a1ca0ad80bc172d2efda34ae542494442dcf48",
"treeHash": "c1be883f8fad6adb0369cef0ac6e6c9bd7f3ec66",
"type": "github"
},
"original": {
Expand All @@ -25,11 +25,11 @@
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1721111394,
"lastModified": 1722320953,
"owner": "nix-community",
"repo": "fenix",
"rev": "e63599e3186cfb3284933bc815d33a509addd00e",
"treeHash": "bacc5edad576bf49c31ef3ff3d3dbd9d37e51f1f",
"rev": "483df76def3e5010d709aa3a0418ba2088503994",
"treeHash": "693d543cc59529f26fc53efcc80230e4e260cbd4",
"type": "github"
},
"original": {
Expand Down Expand Up @@ -109,11 +109,11 @@
},
"nixpkgs-stable_2": {
"locked": {
"lastModified": 1720954236,
"lastModified": 1722087241,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "53e81e790209e41f0c1efa9ff26ff2fd7ab35e27",
"treeHash": "ca1f1273cf201da604f7c704535d4b7fac62cdb2",
"rev": "8c50662509100d53229d4be607f1a3a31157fa12",
"treeHash": "cbc560aaf05dfc49bde55e55f603d7245515b13a",
"type": "github"
},
"original": {
Expand Down Expand Up @@ -158,11 +158,11 @@
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1721048109,
"lastModified": 1722262053,
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "0c95aaa08e5f870d269f0ca13010eda9a4dc3402",
"treeHash": "3d6283b1061f6a295a15a322a482376f52a05d86",
"rev": "a021b85be57d34b1eed687fcafd5d5ec64b2d853",
"treeHash": "a3479dccad2f95206ce18bc32932507cbd32625e",
"type": "github"
},
"original": {
Expand Down
48 changes: 48 additions & 0 deletions hugr-cli/src/extensions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//! Dump standard extensions in serialized form.
use clap::Parser;
use std::{io::Write, path::PathBuf};

/// Dump the standard extensions.
#[derive(Parser, Debug)]
#[clap(version = "1.0", long_about = None)]
#[clap(about = "Write standard extensions.")]
#[group(id = "hugr")]
#[non_exhaustive]
pub struct ExtArgs {
/// Output directory
#[arg(
default_value = ".",
short,
long,
value_name = "OUTPUT",
help = "Output directory."
)]
pub outdir: PathBuf,
}

impl ExtArgs {
/// Write out the standard extensions in serialized form.
/// Qualified names of extensions used to generate directories under the specified output directory.
/// E.g. extension "foo.bar.baz" will be written to "OUTPUT/foo/bar/baz.json".
pub fn run_dump(&self) {
let base_dir = &self.outdir;

for (name, ext) in hugr_core::std_extensions::std_reg().into_iter() {
let mut path = base_dir.clone();
for part in name.split('.') {
path.push(part);
}
path.set_extension("json");

std::fs::create_dir_all(path.clone().parent().unwrap()).unwrap();
// file buffer
let mut file = std::fs::File::create(&path).unwrap();

serde_json::to_writer_pretty(&mut file, &ext).unwrap();

// write newline, for pre-commit end of file check that edits the file to
// add newlines if missing.
file.write_all(b"\n").unwrap();
}
}
}
3 changes: 3 additions & 0 deletions hugr-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use thiserror::Error;
/// We reexport some clap types that are used in the public API.
pub use {clap::Parser, clap_verbosity_flag::Level};

pub mod extensions;
pub mod validate;

/// CLI arguments.
Expand All @@ -16,6 +17,8 @@ pub mod validate;
pub enum CliArgs {
/// Validate and visualize a HUGR file.
Validate(validate::CliArgs),
/// Write standard extensions out in serialized form.
GenExtensions(extensions::ExtArgs),
/// External commands
#[command(external_subcommand)]
External(Vec<OsString>),
Expand Down
Loading

0 comments on commit 5788c28

Please sign in to comment.