Skip to content

Commit 9f0adc7

Browse files
committed
initial
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
0 parents  commit 9f0adc7

22 files changed

Lines changed: 2290 additions & 0 deletions
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Bump minor version
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_run:
6+
workflows: [Publish to mason registry]
7+
types: [completed]
8+
9+
jobs:
10+
bump-minor:
11+
runs-on: ubuntu-latest
12+
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Exit if branch exists
16+
run: |
17+
BRANCH_NAME="update-version"
18+
if git ls-remote --heads origin $BRANCH_NAME | grep -q $BRANCH_NAME; then
19+
echo "Branch $BRANCH_NAME already exists."
20+
exit 1
21+
fi
22+
- name: Create a new branch
23+
run: |
24+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
25+
git config --global user.name "github-actions[bot]"
26+
git checkout -b update-version
27+
git push --set-upstream origin update-version
28+
- name: Get version from Mason.toml
29+
id: previous_version
30+
uses: mikefarah/yq@v4
31+
with:
32+
cmd: yq .brick.version Mason.toml
33+
- name: Bump Minor Version
34+
id: bump_version
35+
run: |
36+
PREVIOUS_VERSION=${{ steps.previous_version.outputs.result }}
37+
MAJOR=$(echo $PREVIOUS_VERSION | cut -d. -f1)
38+
MINOR=$(echo $PREVIOUS_VERSION | cut -d. -f2)
39+
NEW_MINOR=$((MINOR + 1))
40+
NEW_VERSION="$MAJOR.$NEW_MINOR.0"
41+
echo "New version: $NEW_VERSION"
42+
echo "result=$NEW_VERSION" >> $GITHUB_OUTPUT
43+
- name: Update version in Mason.toml
44+
uses: mikefarah/yq@v4
45+
with:
46+
cmd: yq -i '.brick.version="${{ steps.bump_version.outputs.result }}"' Mason.toml
47+
- name: Get name from Mason.toml
48+
id: package_name
49+
uses: mikefarah/yq@v4
50+
with:
51+
cmd: yq .brick.name Mason.toml
52+
- name: Update version in README.md
53+
run: |
54+
NAME=${{ steps.package_name.outputs.result }}
55+
NEW_VERSION=${{ steps.bump_version.outputs.result }}
56+
sed "s/mason add $NAME@[0-9]*\.[0-9]*\.[0-9]*/mason add $NAME@$NEW_VERSION/g" README.md > README.tmp && mv README.tmp README.md
57+
- name: Commit and push changes
58+
run: |
59+
git add Mason.toml
60+
git add README.md
61+
git commit -m "Bump version to ${{ steps.bump_version.outputs.result }}"
62+
git push origin update-version
63+
- name: create pull request
64+
run: >
65+
gh pr create
66+
-B main
67+
-H update-version
68+
--title 'Bump version for next release'
69+
--body 'Bump the version in prep for next release'
70+
env:
71+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎.github/workflows/ci.yml‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ci-${{ github.ref }}
12+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
13+
14+
jobs:
15+
tests:
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
version: [2.7.0, 2.8.0, latest]
20+
runs-on: ubuntu-latest
21+
container:
22+
image: chapel/chapel:${{ matrix.version }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Check the project builds
26+
run: |
27+
mason build
28+
- name: Check the examples build and run
29+
run: |
30+
mason build --example
31+
for example in $(ls example/*.chpl); do
32+
mason run --example $(basename $example);
33+
done
34+
- name: Run mason tests
35+
run: |
36+
mason test --show --parallel
37+
- name: Run chplcheck
38+
run: |
39+
chplcheck src/**/*.chpl
40+
- name: Check undocumented symbols
41+
shell: bash
42+
run: |
43+
shopt -s globstar
44+
chpl_home=$(chpl --print-chpl-home)
45+
CHPL_HOME=$chpl_home $chpl_home/tools/chpldoc/findUndocumentedSymbols --ci src/**/*.chpl

‎.github/workflows/docs.yml‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: build docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
workflow_call:
10+
11+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
18+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
19+
concurrency:
20+
group: "pages"
21+
cancel-in-progress: false
22+
23+
jobs:
24+
build:
25+
runs-on: ubuntu-latest
26+
container:
27+
# TODO: use nightly to get the latest chpldoc features, switch to stable
28+
# when 2.9 is released
29+
image: chapel/chapel:nightly
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
- name: Setup Pages
34+
uses: actions/configure-pages@v5
35+
- name: Build docs
36+
run: |
37+
# TODO: docs builds fail because of examples not being included.
38+
# ignore for now
39+
mason doc || true
40+
- name: Upload artifact
41+
uses: actions/upload-pages-artifact@v3
42+
with:
43+
path: ./doc/
44+
45+
# TODO: where do we deploy the docs to?
46+
# deploy:
47+
# if: github.event_name == 'push' && github.repository == 'chapel-lang/Crypto'
48+
# environment:
49+
# name: github-pages
50+
# url: ${{ steps.deployment.outputs.page_url }}
51+
# runs-on: ubuntu-latest
52+
# needs: build
53+
# steps:
54+
# - name: Deploy to GitHub Pages
55+
# id: deployment
56+
# uses: actions/deploy-pages@v4

‎.github/workflows/publish.yml‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Publish to mason registry
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
create-tag:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- name: Get version from Mason.toml
12+
id: version
13+
uses: mikefarah/yq@v4
14+
with:
15+
cmd: yq .brick.version Mason.toml
16+
- name: Bump version and push tag
17+
id: create_tag
18+
uses: mathieudutour/github-tag-action@v6.2
19+
with:
20+
github_token: ${{ secrets.GITHUB_TOKEN }}
21+
custom_tag: ${{ steps.version.outputs.result }}
22+
tag_prefix: "v"
23+
create_annotated_tag: true
24+
push-to-mason-registry:
25+
needs: create-tag
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
path: source-repo
31+
- name: Get version from Mason.toml
32+
id: version
33+
uses: mikefarah/yq@v4
34+
with:
35+
cmd: yq .brick.version source-repo/Mason.toml
36+
- name: Get package name
37+
id: package_name
38+
uses: mikefarah/yq@v4
39+
with:
40+
cmd: yq .brick.name source-repo/Mason.toml
41+
- name: Checkout mason-registry fork
42+
uses: actions/checkout@v4
43+
with:
44+
repository: chapelautomaton/mason-registry
45+
token: ${{ secrets.MASON_PUBLISH_TOKEN }}
46+
path: mason-registry
47+
- name: Create branch and add package
48+
run: |
49+
VERSION="${{ steps.version.outputs.result }}"
50+
PACKAGE_NAME="${{ steps.package_name.outputs.result }}"
51+
cd mason-registry
52+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
53+
git config user.name "github-actions[bot]"
54+
git checkout -b "${PACKAGE_NAME}-${VERSION}"
55+
mkdir -p "Bricks/${PACKAGE_NAME}"
56+
cp ../source-repo/Mason.toml "Bricks/${PACKAGE_NAME}/${VERSION}.toml"
57+
git add .
58+
git commit -m "Add ${PACKAGE_NAME} ${VERSION}"
59+
- name: Push changes
60+
uses: ad-m/github-push-action@v1
61+
with:
62+
github_token: ${{ secrets.MASON_PUBLISH_TOKEN }}
63+
repository: chapelautomaton/mason-registry
64+
branch: "${{ steps.package_name.outputs.result }}-${{ steps.version.outputs.result }}"
65+
directory: mason-registry
66+
- name: Create pull request
67+
run: >
68+
gh pr create
69+
--repo chapel-lang/mason-registry
70+
--head "chapelautomaton:${{ steps.package_name.outputs.result }}-${{ steps.version.outputs.result }}"
71+
--base master
72+
--title "Add ${{ steps.package_name.outputs.result }} ${{ steps.version.outputs.result }}"
73+
--body "Add ${{ steps.package_name.outputs.result }} version ${{ steps.version.outputs.result }} to the mason registry"
74+
env:
75+
GH_TOKEN: ${{ secrets.MASON_PUBLISH_TOKEN }}
76+

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target/
2+
Mason.lock
3+
doc/

‎Mason.toml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
[brick]
3+
name = "Crypto"
4+
version = "0.1.0"
5+
chplVersion = "2.8.0"
6+
type = "library"
7+
source = "https://github.com/chapel-lang/Crypto"
8+
authors = ["HPE", "Jade Abraham"]
9+
copyrightYear = "2004"
10+
license = "Apache-2.0"
11+
12+
[dependencies]
13+
14+
[system]
15+
openssl = "*"

‎README.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Crypto
2+
3+
A cryptographic library based on 'OpenSSL'.
4+
5+
This module provides a cryptographic library based on
6+
[OpenSSL](https://www.openssl.org/).
7+
8+
## Installation
9+
10+
Add Crypto as a Mason dependency:
11+
12+
```bash
13+
mason add Crypto@0.1.0
14+
```
15+
16+
## Usage
17+
18+
```chapel
19+
use Crypto;
20+
21+
var sha = new Hash(Digest.SHA256);
22+
var buf = new CryptoBuffer(b"Hello, World!");
23+
var digest = sha.getDigest(buf);
24+
25+
writeln(digest.toHexString());
26+
```
27+
28+
## License
29+
30+
See [Mason.toml](Mason.toml).

‎example/shasum.chpl‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use Crypto;
2+
use IO;
3+
proc main(args: [] string) {
4+
if args.size == 1 {
5+
var shasum = shasumStdin();
6+
writeln(shasum, " -");
7+
} else {
8+
for f in args[1..] {
9+
var shasum = shasumFile(f);
10+
writeln(shasum, " ", f);
11+
}
12+
}
13+
}
14+
15+
const BUF_SIZE = 1024;
16+
17+
proc shasumFile(filename: string): string do
18+
return shasumReader(openReader(filename));
19+
proc shasumStdin(): string do
20+
return shasumReader(stdin);
21+
22+
proc shasumReader(r: fileReader(?)): string {
23+
var sha = new StreamingHash(Digest.SHA256);
24+
var buf: bytes;
25+
while r.readBytes(buf, BUF_SIZE) {
26+
var bufCrypto = new LocalBorrowedCryptoBuffer(buf);
27+
sha.update(bufCrypto);
28+
}
29+
var digest = sha.finish();
30+
return digest.toHexString();
31+
}

‎shasumMain.chpl‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use Crypto;
2+
use IO;
3+
proc main(args: [] string) {
4+
if args.size == 1 {
5+
var shasum = shasumStdin();
6+
writeln(shasum, " -");
7+
} else {
8+
for f in args[1..] {
9+
var shasum = shasumFile(f);
10+
writeln(shasum, " ", f);
11+
}
12+
}
13+
}
14+
15+
proc shasumFile(filename: string): string do
16+
return shasumReader(openReader(filename));
17+
proc shasumStdin(): string do
18+
return shasumReader(stdin);
19+
20+
proc shasumReader(r: fileReader(?)): string {
21+
var sha = new Hash(Digest.SHA256);
22+
var buf: bytes = r.readAll(bytes);
23+
var bufCrypto = new CryptoBuffer(buf);
24+
var digest = sha.getDigest(bufCrypto);
25+
return digest.toHexString();
26+
}

0 commit comments

Comments
 (0)