Skip to content

Commit 92a1256

Browse files
authored
Initial commit
0 parents  commit 92a1256

46 files changed

Lines changed: 2109 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Install nbcommands if not already installed. More info: https://github.com/vinayak-mehta/nbcommands
2+
if ! command -v nbgrep &> /dev/null; then
3+
echo "nbcommands is not installed. Installing..."
4+
pip install nbcommands
5+
fi
6+
7+
# Specify the path for the output Python file
8+
mkdir -p ./.github/workflows/testing
9+
touch ./.github/workflows/testing/test_import_libraries.py
10+
PYTHON_FILE="./.github/workflows/testing/test_import_libraries.py"
11+
12+
# Remove the output file if it already exists
13+
rm -f "$PYTHON_FILE"
14+
15+
# Search for *.ipynb files recursively in all folders
16+
find . -type f -name '*.ipynb' -print0 |
17+
while IFS= read -r -d '' file; do
18+
# Extract import statements from Jupyter notebooks
19+
# new one catch the import xx.x as y and removing the space
20+
# nbgrep "(?:from\s+(\w+(?:\.\w+)*)\s+import\s+(\*|\w+)(?:\s+as\s+\w+)?(?:,s*\w+(?:\\s+as\s+\w+)?)*|import\s+(\w+(?:\.\w+)*)\s+as\s+\w+(?:,\s*\w+(?:\s+as\s+\w+)?)*)" "$file" | grep -v 'nbgrep:' | awk -F ':' '{sub(/^[^:]*:[^:]*:line [0-9]+:/, " ", $0)}1'| sed 's/^[[:space:]]*//'
21+
nbgrep "(?:from\s+(\w+(?:\.\w+)*)\s+import\s+(\*|\w+)(?:\s+as\s+\w+)?(?:,\s*\w+(?:\s+as\s+\w+)?)*|import\s+(\w+(?:\.\w+)*)\s+as\s+\w+(?:,\s*\w+(?:\s+as\s+\w+)?)*)|(?:^|\n)import\s+(\w+(?:\.\w+)*)\s+" "$file" | grep -v 'nbgrep:' | awk -F ':' '{sub(/^[^:]*:[^:]*:line [0-9]+:/, " ", $0)}1'| sed 's/^[[:space:]]*//'
22+
23+
24+
done | sort -u > "$PYTHON_FILE"
25+
echo "<<<<<<< All extract import statements from Jupyter notebooks >>>>>>"
26+
cat "$PYTHON_FILE"
27+
28+
29+
# Generate test function in test.py
30+
# echo "#!/usr/bin/env python" > "$PYTHON_FILE.tmp"
31+
echo "" >> "$PYTHON_FILE.tmp"
32+
echo "def test_import_libraries():" >> "$PYTHON_FILE.tmp"
33+
echo " try:" >> "$PYTHON_FILE.tmp"
34+
grep "import" "$PYTHON_FILE" | sed 's/^/ /' >> "$PYTHON_FILE.tmp"
35+
echo " except ImportError as e:" >> "$PYTHON_FILE.tmp"
36+
echo " # If any of the libraries cannot be imported, the test will fail" >> "$PYTHON_FILE.tmp"
37+
echo " assert False, f\"Failed to import library: {e}\"" >> "$PYTHON_FILE.tmp"
38+
echo "" >> "$PYTHON_FILE.tmp"
39+
echo " # If all libraries are imported successfully, the test passes" >> "$PYTHON_FILE.tmp"
40+
echo " assert True" >> "$PYTHON_FILE.tmp"
41+
42+
# Move the temporary file to the final location
43+
mv "$PYTHON_FILE.tmp" "$PYTHON_FILE"
44+
cat "$PYTHON_FILE"
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Add Issues to project
2+
# This workflow runs whenever a issue in the repository is marked as "closed".
3+
on:
4+
issues:
5+
types:
6+
- closed
7+
jobs:
8+
track_issue:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Generate token
12+
id: generate_token
13+
uses: actions/create-github-app-token@v1.7.0
14+
with:
15+
app-id: ${{ secrets.DS_PROJECT_BOARD_APP_ID }}
16+
private-key: ${{ secrets.DS_PROJECT_BOARD_APP_PEM }}
17+
# Sets environment variables for this step.
18+
- name: Get project data
19+
env:
20+
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
21+
ORGANIZATION: neuefische
22+
PROJECT_NUMBER: 7
23+
# Uses GitHub CLI to query the API for the ID of the project and return the name and ID of the first 20 fields in the project. `fields` returns a union and the query uses inline fragments (`... on`) to return information about any `ProjectV2Field` and `ProjectV2SingleSelectField` fields. The response is stored in a file called `project_data.json`.
24+
run: |
25+
gh api graphql -f query='
26+
query($org: String!, $number: Int!) {
27+
organization(login: $org){
28+
projectV2(number: $number) {
29+
id
30+
fields(first:20) {
31+
nodes {
32+
... on ProjectV2Field {
33+
id
34+
name
35+
}
36+
... on ProjectV2SingleSelectField {
37+
id
38+
name
39+
options {
40+
id
41+
name
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
49+
50+
# Parses the response from the API query and stores the relevant IDs as environment variables. Modify this to get the ID for different fields or options.
51+
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV
52+
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
53+
echo 'DONE_OPTION_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="Done") |.id' project_data.json) >> $GITHUB_ENV
54+
55+
# Sets environment variables for this step. `GH_TOKEN` is the token generated in the first step. `ISSUE_ID` is the ID of the issue that triggered this workflow.
56+
- name: Add Issue to project
57+
env:
58+
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
59+
ISSUE_ID: ${{ github.event.issue.node_id }}
60+
# Uses GitHub CLI and the API to add the issue that triggered this workflow to the project. The `jq` flag parses the response to get the ID of the closed item.
61+
run: |
62+
item_id="$( gh api graphql -f query='
63+
mutation($project:ID!, $issue:ID!) {
64+
addProjectV2ItemById(input: {projectId: $project, contentId: $issue}) {
65+
item {
66+
id
67+
}
68+
}
69+
}' -f project=$PROJECT_ID -f issue=$ISSUE_ID --jq '.data.addProjectV2ItemById.item.id')"
70+
71+
# Stores the ID of the created item as an environment variable.
72+
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
73+
74+
75+
# Sets environment variables for this step. `GH_TOKEN` is the token generated in the first step.
76+
- name: Set fields
77+
env:
78+
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
79+
# Sets the value of the `Status` field to `In Progress`.
80+
run: |
81+
gh api graphql -f query='
82+
mutation (
83+
$project: ID!
84+
$item: ID!
85+
$status_field: ID!
86+
$status_value: String!
87+
) {
88+
set_status: updateProjectV2ItemFieldValue(input: {
89+
projectId: $project
90+
itemId: $item
91+
fieldId: $status_field
92+
value: {
93+
singleSelectOptionId: $status_value
94+
}
95+
}) {
96+
projectV2Item {
97+
id
98+
}
99+
}
100+
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=${{ env.DONE_OPTION_ID }} --silent
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Add Issues to project
2+
# This workflow runs whenever a issue in the repository is marked as "opened".
3+
on:
4+
issues:
5+
types:
6+
- opened
7+
jobs:
8+
track_issue:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Generate token
12+
id: generate_token
13+
uses: actions/create-github-app-token@v1.7.0
14+
with:
15+
app-id: ${{ secrets.DS_PROJECT_BOARD_APP_ID }}
16+
private-key: ${{ secrets.DS_PROJECT_BOARD_APP_PEM }}
17+
# Sets environment variables for this step.
18+
- name: Get project data
19+
env:
20+
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
21+
ORGANIZATION: neuefische
22+
PROJECT_NUMBER: 7
23+
# Uses GitHub CLI to query the API for the ID of the project and return the name and ID of the first 20 fields in the project. `fields` returns a union and the query uses inline fragments (`... on`) to return information about any `ProjectV2Field` and `ProjectV2SingleSelectField` fields. The response is stored in a file called `project_data.json`.
24+
run: |
25+
gh api graphql -f query='
26+
query($org: String!, $number: Int!) {
27+
organization(login: $org){
28+
projectV2(number: $number) {
29+
id
30+
fields(first:20) {
31+
nodes {
32+
... on ProjectV2Field {
33+
id
34+
name
35+
}
36+
... on ProjectV2SingleSelectField {
37+
id
38+
name
39+
options {
40+
id
41+
name
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
49+
50+
# Parses the response from the API query and stores the relevant IDs as environment variables. Modify this to get the ID for different fields or options.
51+
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV
52+
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
53+
echo 'TODO_OPTION_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="Todo (Ready)") |.id' project_data.json) >> $GITHUB_ENV
54+
55+
# Sets environment variables for this step. `GH_TOKEN` is the token generated in the first step. ISSUE_ID` is the ID of the issue that triggered this workflow.
56+
- name: Add Issue to project
57+
env:
58+
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
59+
ISSUE_ID: ${{ github.event.issue.node_id }}
60+
# Uses GitHub CLI and the API to add the issue that triggered this workflow to the project. The `jq` flag parses the response to get the ID of the created item.
61+
run: |
62+
item_id="$( gh api graphql -f query='
63+
mutation($project:ID!, $issue:ID!) {
64+
addProjectV2ItemById(input: {projectId: $project, contentId: $issue}) {
65+
item {
66+
id
67+
}
68+
}
69+
}' -f project=$PROJECT_ID -f issue=$ISSUE_ID --jq '.data.addProjectV2ItemById.item.id')"
70+
71+
# Stores the ID of the created item as an environment variable.
72+
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
73+
74+
75+
# Sets environment variables for this step. `GH_TOKEN` is the token generated in the first step.
76+
- name: Set fields
77+
env:
78+
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
79+
# Sets the value of the `Status` field to `In Progress`.
80+
run: |
81+
gh api graphql -f query='
82+
mutation (
83+
$project: ID!
84+
$item: ID!
85+
$status_field: ID!
86+
$status_value: String!
87+
) {
88+
set_status: updateProjectV2ItemFieldValue(input: {
89+
projectId: $project
90+
itemId: $item
91+
fieldId: $status_field
92+
value: {
93+
singleSelectOptionId: $status_value
94+
}
95+
}) {
96+
projectV2Item {
97+
id
98+
}
99+
}
100+
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=${{ env.TODO_OPTION_ID }} --silent
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Add PR to project
2+
# This workflow runs whenever a pull request in the repository is marked as "opened".
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
jobs:
8+
track_pr:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Generate token
12+
id: generate_token
13+
uses: actions/create-github-app-token@v1.7.0
14+
with:
15+
app-id: ${{ secrets.DS_PROJECT_BOARD_APP_ID }}
16+
private-key: ${{ secrets.DS_PROJECT_BOARD_APP_PEM }}
17+
# Sets environment variables for this step.
18+
- name: Get project data
19+
env:
20+
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
21+
ORGANIZATION: neuefische
22+
PROJECT_NUMBER: 7
23+
# Uses GitHub CLI to query the API for the ID of the project and return the name and ID of the first 20 fields in the project. `fields` returns a union and the query uses inline fragments (`... on`) to return information about any `ProjectV2Field` and `ProjectV2SingleSelectField` fields. The response is stored in a file called `project_data.json`.
24+
run: |
25+
gh api graphql -f query='
26+
query($org: String!, $number: Int!) {
27+
organization(login: $org){
28+
projectV2(number: $number) {
29+
id
30+
fields(first:20) {
31+
nodes {
32+
... on ProjectV2Field {
33+
id
34+
name
35+
}
36+
... on ProjectV2SingleSelectField {
37+
id
38+
name
39+
options {
40+
id
41+
name
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
49+
50+
# Parses the response from the API query and stores the relevant IDs as environment variables. Modify this to get the ID for different fields or options.
51+
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV
52+
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
53+
echo 'PROGRESS_OPTION_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="In Progress") |.id' project_data.json) >> $GITHUB_ENV
54+
55+
# Sets environment variables for this step. `GH_TOKEN` is the token generated in the first step. `PR_ID` is the ID of the pull request that triggered this workflow.
56+
- name: Add PR to project
57+
env:
58+
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
59+
PR_ID: ${{ github.event.pull_request.node_id }}
60+
# Uses GitHub CLI and the API to add the pull request that triggered this workflow to the project. The `jq` flag parses the response to get the ID of the created item.
61+
run: |
62+
item_id="$( gh api graphql -f query='
63+
mutation($project:ID!, $pr:ID!) {
64+
addProjectV2ItemById(input: {projectId: $project, contentId: $pr}) {
65+
item {
66+
id
67+
}
68+
}
69+
}' -f project=$PROJECT_ID -f pr=$PR_ID --jq '.data.addProjectV2ItemById.item.id')"
70+
71+
# Stores the ID of the created item as an environment variable.
72+
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
73+
74+
75+
# Sets environment variables for this step. `GH_TOKEN` is the token generated in the first step.
76+
- name: Set fields
77+
env:
78+
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
79+
# Sets the value of the `Status` field to `In Progress`.
80+
run: |
81+
gh api graphql -f query='
82+
mutation (
83+
$project: ID!
84+
$item: ID!
85+
$status_field: ID!
86+
$status_value: String!
87+
) {
88+
set_status: updateProjectV2ItemFieldValue(input: {
89+
projectId: $project
90+
itemId: $item
91+
fieldId: $status_field
92+
value: {
93+
singleSelectOptionId: $status_value
94+
}
95+
}) {
96+
projectV2Item {
97+
id
98+
}
99+
}
100+
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=${{ env.PROGRESS_OPTION_ID }} --silent

0 commit comments

Comments
 (0)