Skip to content

Commit

Permalink
Merge branch 'master' into cli-wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjaypatel committed Nov 9, 2024
2 parents 2b18893 + db64400 commit 212d921
Show file tree
Hide file tree
Showing 260 changed files with 19,949 additions and 5,778 deletions.
33 changes: 33 additions & 0 deletions .github/actions/contributions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Needs Attention Labeler"
description: "Applies 'needs attention' and other labels to PRs or issues"
inputs:
repo-token:
description: "GitHub token with repository permissions"
required: true
response-required-label:
description: "Label to apply when response is required"
required: true
needs-attention-label:
description: "Label to apply when attention is needed"
required: true
outputs:
result:
description: "Result of the labeling action"
value: ${{ steps.needs-attention.outputs.result }}
runs:
using: "composite"
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Apply Needs Attention Label
uses: hramos/[email protected]
with:
repo-token: ${{ inputs.repo-token }}
response-required-label: ${{ inputs.response-required-label }}
needs-attention-label: ${{ inputs.needs-attention-label }}
id: needs-attention

- name: Set output result
shell: bash
run: echo "result=${{ steps.needs-attention.outputs.result }}" >> $GITHUB_OUTPUT
36 changes: 28 additions & 8 deletions .github/actions/style/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ description: 'Run linter and formatter'
runs:
using: 'composite'
steps:
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45

# Check for Markdown/MDX changes
- name: Check for Markdown/MDX changes
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
shell: bash
run: |
echo "Checking for Markdown/MDX changes..."
if git diff --cached --name-only | grep -qE '\.mdx?$'; then
if echo "$ALL_CHANGED_FILES" | grep -qE '\.mdx?$'; then
if ! pnpm check:md; then
echo "Markdown or MDX files are not properly formatted."
exit 1 # Exit with a non-zero status code to indicate failure
Expand All @@ -17,17 +23,25 @@ runs:
# Check for Rust code changes and run Rust formatting
- name: Check for Rust code changes
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
shell: bash
run: |
echo "Checking for Rust code changes..."
if git diff --cached --name-only | grep -qE '\.rs$'; then
if echo "$ALL_CHANGED_FILES" | grep -q '\.rs$'; then
echo "Running checks for the Rust code..."
rustup install nightly
# Install the nightly toolchain
rustup toolchain install nightly
# Install rustfmt for the nightly toolchain
rustup component add rustfmt --toolchain nightly
if ! cargo +nightly fmt -- --check; then
echo "Rust code is not properly formatted."
exit 1 # Exit with a non-zero status code if formatting fails
fi
if ! cargo clippy -- -D warnings; then
if ! cargo clippy -- -A warnings; then
echo "Rust code is not properly linted."
exit 1 # Exit with a non-zero status code if formatting fails
fi
Expand All @@ -36,9 +50,12 @@ runs:
# Check for changes in the 'node-ui' directory and run formatting/linting
- name: Check for changes in node-ui
shell: bash
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo "Checking for changes in node-ui..."
if git diff --cached --name-only | grep -q '^node-ui/'; then
echo "Checking for changes in node-ui files"
if echo "$ALL_CHANGED_FILES" | grep -q '^node-ui/'; then
echo "Running checks for the node-ui..."
cd node-ui
if ! pnpm prettier:check .; then
echo "Prettier found unformatted files in node-ui."
Expand All @@ -54,9 +71,12 @@ runs:
# Check for changes in the 'packages/calimero-sdk' directory and run formatting/linting
- name: Check for changes in calimero-sdk
shell: bash
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo "Checking for changes in calimero-sdk..."
if git diff --cached --name-only | grep -q '^packages/calimero-sdk/'; then
echo "Checking for changes in calimero-sdk files"
if echo "$ALL_CHANGED_FILES" | grep -q '^packages/calimero-sdk/'; then
echo "Running checks for the calimero-sdk files"
cd packages/calimero-sdk
if ! pnpm prettier:check .; then
echo "Prettier found unformatted files in calimero-sdk."
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/contributions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Configure Issue and PR labels

on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]

jobs:
applyNeedsAttentionLabel:
name: Apply Needs Attention
runs-on: ubuntu-latest
permissions:
contents: read # for actions/checkout to fetch code
issues: write # for hramos/needs-attention to label issues
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Apply Needs Attention Label
id: needs-attention
uses: ./.github/actions/contributions
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
response-required-label: "waiting-for-author-feedback"
needs-attention-label: "needs-team-review"
- name: Result
run: echo '${{ steps.needs-attention.outputs.result }}'
151 changes: 151 additions & 0 deletions .github/workflows/new-issue-or-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
name: Label Issues and PRs on Open/Reopen

on:
issues:
types: [opened, reopened] # Trigger when an issue is opened or reopened
pull_request_target:
types: [opened, reopened]
branches:
- master # Trigger when PRs are opened or reopened targeting the master branch

jobs:
labelIssuePR:
name: Apply Label to Issues and PRs
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Add Label to Issue or PR
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Check if it's an issue or a PR
if (context.eventName === 'issues') {
// Add label to issue
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['needs-team-review']
});
} else if (context.eventName === 'pull_request') {
// Add label to PR
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: ['needs-team-review']
});
}
result-encoding: string
id: result
- name: Get result
run: echo "${{steps.result.outputs.result}}"

determine-contribution-type:
name: Apply Label to Issues and PRs
runs-on: ubuntu-latest
outputs:
is_external: ${{ steps.determine_if_external.outputs.is_external }}
contribution_author: ${{ steps.get_author.outputs.result }}

steps:
- name: Get Author Information
id: get_author
uses: actions/github-script@v7

with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const authorLogin = context.payload.pull_request ? context.payload.pull_request.user.login : context.payload.issue.user.login;
return authorLogin;
- name: Get Organization Members
id: get_org_members
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const org = context.repo.owner; // Organization name
let allMembers = [];
let page = 1;
while (true) {
const membersPage = await github.rest.orgs.listMembers({
org: org,
page: page,
per_page: 100
});
allMembers = allMembers.concat(membersPage.data);
if (membersPage.data.length < 100) {
break; // No more pages to fetch
}
page++;
}
return allMembers.map(member => member.login);
- name: Determine if Author is External
id: determine_if_external
run: |
echo "Author: ${{ steps.get_author.outputs.result }}"
echo "Organization Members: ${{ steps.get_org_members.outputs.result }}"
AUTHOR="${{ steps.get_author.outputs.result }}"
ORG_MEMBERS="${{ steps.get_org_members.outputs.result }}"
if echo "$ORG_MEMBERS" | grep -q "$AUTHOR"; then
echo "The author $AUTHOR is a member of the organization.";
echo "is_external=false" >> $GITHUB_OUTPUT
else
echo "The author $AUTHOR is an external contributor.";
echo "is_external=true" >> $GITHUB_OUTPUT
fi
- name: Add External Label if Necessary
if: steps.determine_if_external.outputs.is_external == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issueOrPr = context.payload.issue || context.payload.pull_request;
const issueNumber = issueOrPr.number; // PR number for PRs and issue number for issues
const owner = context.repo.owner;
const repo = context.repo.repo;
await github.rest.issues.addLabels({
owner: owner,
repo: repo,
issue_number: issueNumber,
labels: ['external']
});
notify-slack-on-external-contribution:
runs-on: ubuntu-latest
needs: [determine-contribution-type]
if: needs.determine-contribution-type.outputs.is_external == 'true'
steps:
- name: Determine Contribution Type
id: contribution_type
run: |
if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
echo "contribution_type=Pull Request" >> $GITHUB_OUTPUT
else
echo "contribution_type=Issue" >> $GITHUB_OUTPUT
fi
- name: Notify external contribution
uses: "ravsamhq/[email protected]"
with:
status: failure
notification_title: "New external contribution in <${{ github.server_url }}/${{ github.repository }}/${{ github.ref_name }}|${{ github.repository }}>"
message_format: "*${{ steps.contribution_type.outputs.contribution_type }}* contribution by *${{ needs.determine-contribution-type.outputs.contribution_author }}*: <${{ github.event.pull_request.html_url || github.event.issue.html_url }}|Open contribution>"
footer: "Linked Repo <${{ github.server_url }}/${{ github.repository }}|${{ github.repository }}> | <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View trigger>"
env:
SLACK_WEBHOOK_URL: ${{ secrets.EXTERNAL_CONTRIBUTION_SLACK }}
41 changes: 35 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,45 @@ on:

env:
CARGO_TERM_COLOR: always
CARGO_HOME:
RUSTUP_HOME:
PNPM_HOME:
ALT_HOME:
STAGE_DIR:

jobs:
setup:
name: Project setup
runs-on: ubuntu-latest
steps:
- name: Prepare
run: |
export STAGE_DIR="$(dirname $GITHUB_WORKSPACE)"
echo "STAGE_DIR=$STAGE_DIR" >> $GITHUB_ENV
export ALT_HOME="$STAGE_DIR/.home"
echo "ALT_HOME=$ALT_HOME" >> $GITHUB_ENV
- name: Maximize build space
uses: easimon/maximize-build-space@v10
with:
build-mount-path: ${{ env.STAGE_DIR }}
root-reserve-mb: 4096

- name: Relocate environment
run: |
echo "CARGO_HOME=$ALT_HOME/.cargo" >> $GITHUB_ENV
echo "RUSTUP_HOME=$ALT_HOME/.rustup" >> $GITHUB_ENV
echo "PNPM_HOME=$ALT_HOME/.pnpm" >> $GITHUB_ENV
mkdir $ALT_HOME
mv ~/.cargo $ALT_HOME
mv ~/.rustup $ALT_HOME
echo "$ALT_HOME/.cargo/bin" | cat - $GITHUB_PATH > temp && mv temp $GITHUB_PATH
- name: Checkout code
uses: actions/checkout@v4

# Install Node.js (version 20) and pnpm
# Install Node.js (version 20) and pnpm
- name: Set up Node.js
uses: actions/setup-node@v2
with:
Expand All @@ -33,15 +62,15 @@ jobs:
- name: Build node-ui
run: pnpm --filter ./node-ui run build

- name: Run code style checks
uses: ./.github/actions/style

- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: rustup toolchain install stable --profile minimal
- name: Setup rust toolchain
run: rustup toolchain install stable --profile minimal

- name: Setup rust cache
uses: Swatinem/rust-cache@v2

- name: Run code style checks
uses: ./.github/actions/style

- name: Build
run: cargo build --verbose

Expand Down
Loading

0 comments on commit 212d921

Please sign in to comment.