-
Notifications
You must be signed in to change notification settings - Fork 8
chore: add github actions (#3) #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ba775c1
chore: triggering github actions (#3)
jasuwienas 613ddd2
chore: triggering github actions (#3)
jasuwienas 5e20b38
chore: triggering github actions (#3)
jasuwienas 18ea00a
feat: making gh actions work correctly with solo
jasuwienas 86f5127
feat: make solo work in pipelines (#2)
jasuwienas c752dc4
feat: fining gh action (#2)
jasuwienas 3465af3
chore: set proper dispatch conditions (#3)
jasuwienas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| version: 2 | ||
| updates: | ||
| - package-ecosystem: "github-actions" | ||
| directory: "/" | ||
| schedule: | ||
| interval: "daily" | ||
| open-pull-requests-limit: 10 | ||
|
|
||
| - package-ecosystem: docker | ||
| directory: / | ||
| schedule: | ||
| interval: daily | ||
|
|
||
| - package-ecosystem: npm | ||
| directory: / | ||
| schedule: | ||
| interval: daily |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| relay: | ||
| config: | ||
| DEBUG_API_ENABLED: "true" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| changelog: | ||
| exclude: | ||
| labels: ['wontfix', 'question', 'duplicate', 'invalid'] | ||
| categories: | ||
| - title: 'Enhancements' | ||
| labels: ['enhancement'] | ||
| - title: 'Bug Fixes' | ||
| labels: ['bug'] | ||
| - title: 'Documentation' | ||
| labels: ['documentation'] | ||
| - title: 'Dependency Upgrades' | ||
| labels: ['dependencies'] | ||
| - title: 'Internal Changes' | ||
| labels: ['internal', 'github_action'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,279 @@ | ||
| const axios = require('axios'); | ||
|
|
||
| const githubToken = process.env.GITHUB_TOKEN; | ||
| const { GITHUB_REPOSITORY, GITHUB_PR_NUMBER } = process.env; | ||
|
|
||
| const [owner, repo] = GITHUB_REPOSITORY.split('/'); | ||
|
|
||
| async function getPRDetails(prNumber) { | ||
| const url = `https://api.github.com/repos/${owner}/${repo}/pulls/${prNumber}`; | ||
| try { | ||
| const response = await axios.get(url, { | ||
| headers: { | ||
| Authorization: `token ${githubToken}`, | ||
| }, | ||
| }); | ||
| return response.data; | ||
| } catch (error) { | ||
| if (error.response && error.response.status === 404) { | ||
| console.log(`PR #${prNumber} not found in repository ${owner}/${repo}, skipping...`); | ||
| return null; | ||
| } else { | ||
| throw error; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async function getIssueDetails(issueOwner, issueRepo, issueNumber) { | ||
| try { | ||
| const url = `https://api.github.com/repos/${issueOwner}/${issueRepo}/issues/${issueNumber}`; | ||
| const response = await axios.get(url, { | ||
| headers: { | ||
| Authorization: `token ${githubToken}`, | ||
| }, | ||
| }); | ||
| return response.data; | ||
| } catch (error) { | ||
| if (error.response && error.response.status === 404) { | ||
| console.log(`Issue #${issueNumber} not found in repository ${issueOwner}/${issueRepo}, skipping...`); | ||
| return null; | ||
| } else { | ||
| throw error; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async function getContributors() { | ||
| const url = `https://api.github.com/repos/${owner}/${repo}/contributors`; | ||
| const response = await axios.get(url, { | ||
| headers: { | ||
| Authorization: `token ${githubToken}`, | ||
| }, | ||
| }); | ||
| return response.data; | ||
| } | ||
|
|
||
| function stripHTMLTags(text) { | ||
| return text.replace(/<\/?[^>]+(>|$)/g, ''); | ||
| } | ||
|
|
||
| function removeCodeBlocks(text) { | ||
| // Remove fenced code blocks (triple backticks or tildes) | ||
| text = text.replace(/```[\s\S]*?```/g, ''); | ||
| text = text.replace(/~~~[\s\S]*?~~~/g, ''); | ||
| // Remove inline code (single backticks) | ||
| text = text.replace(/`[^`]*`/g, ''); | ||
| return text; | ||
| } | ||
|
|
||
| function extractPRReferences(text) { | ||
| // Regex to match PR references with any number of digits | ||
| const prRegex = | ||
| /(?:^|\s)(?:Fixes|Closes|Resolves|See|PR|Pull Request)?\s*(?:https?:\/\/github\.com\/([\w.-]+)\/([\w.-]+)\/pull\/(\d+)|([\w.-]+)\/([\w.-]+)#(\d+)|#(\d+))(?!\w)/gm; | ||
| const matches = []; | ||
| let match; | ||
| while ((match = prRegex.exec(text)) !== null) { | ||
| const refOwner = match[1] || match[4] || owner; | ||
| const refRepo = match[2] || match[5] || repo; | ||
| const prNumber = match[3] || match[6] || match[7]; | ||
| matches.push({ | ||
| owner: refOwner, | ||
| repo: refRepo, | ||
| prNumber, | ||
| }); | ||
| } | ||
| return matches; | ||
| } | ||
|
|
||
| function extractIssueReferences(text) { | ||
| // Regex to match issue references with any number of digits | ||
| // Supports 'Fixes #123', 'owner/repo#123', 'https://github.com/owner/repo/issues/123' | ||
| const issueRegex = | ||
| /(?:^|\s)(?:Fixes|Closes|Resolves|See|Issue)?\s*(?:(?:https?:\/\/github\.com\/([\w.-]+)\/([\w.-]+)\/issues\/(\d+))|([\w.-]+)\/([\w.-]+)#(\d+)|#(\d+))(?!\w)/gm; | ||
| const issues = []; | ||
| let match; | ||
| while ((match = issueRegex.exec(text)) !== null) { | ||
| const issueOwner = match[1] || match[4] || owner; | ||
| const issueRepo = match[2] || match[5] || repo; | ||
| const issueNumber = match[3] || match[6] || match[7]; | ||
| issues.push({ | ||
| owner: issueOwner, | ||
| repo: issueRepo, | ||
| issueNumber, | ||
| }); | ||
| } | ||
| return issues; | ||
| } | ||
|
|
||
| function cleanText(text) { | ||
| let cleanText = text; | ||
| cleanText = stripHTMLTags(cleanText); | ||
| cleanText = removeCodeBlocks(cleanText); | ||
| return cleanText; | ||
| } | ||
|
|
||
| async function checkPRLabelsAndMilestone(pr) { | ||
| const { labels: prLabels, milestone: prMilestone } = pr; | ||
|
|
||
| if (!prLabels || prLabels.length === 0) { | ||
| throw new Error('The PR has no labels.'); | ||
| } | ||
| if (!prMilestone) { | ||
| throw new Error('The PR has no milestone.'); | ||
| } | ||
| } | ||
|
|
||
| function isDependabotOrSnykPR(pr) { | ||
| return ((pr.user.login === 'dependabot[bot]') || (pr.user.login === 'swirlds-automation')); | ||
| } | ||
|
|
||
| async function processIssueReferencesInText(text) { | ||
| const issueReferences = extractIssueReferences(text); | ||
|
|
||
| let hasValidIssueReference = false; | ||
|
|
||
| if (issueReferences.length > 0) { | ||
| for (const issueRef of issueReferences) { | ||
| // Only process issues from the same repository | ||
| if (issueRef.owner === owner && issueRef.repo === repo) { | ||
| hasValidIssueReference = true; | ||
| const issue = await getIssueDetails(issueRef.owner, issueRef.repo, issueRef.issueNumber); | ||
| if (issue) { | ||
| const { labels: issueLabels, milestone: issueMilestone } = issue; | ||
|
|
||
| if (!issueLabels || issueLabels.length === 0) { | ||
| throw new Error(`Associated issue #${issueRef.issueNumber} has no labels.`); | ||
| } | ||
| if (!issueMilestone) { | ||
| throw new Error(`Associated issue #${issueRef.issueNumber} has no milestone.`); | ||
| } | ||
| } | ||
| } else { | ||
| console.log( | ||
| `Issue #${issueRef.issueNumber} is from a different repository (${issueRef.owner}/${issueRef.repo}), skipping...` | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| if (!hasValidIssueReference) { | ||
| throw new Error('The PR description must reference at least one issue from the current repository.'); | ||
| } else { | ||
| console.log('All associated issues have labels and milestones.'); | ||
| } | ||
| } else { | ||
| throw new Error('The PR description must reference at least one issue from the current repository.'); | ||
| } | ||
| } | ||
|
|
||
| async function processPRReferencesInText(text, contributors) { | ||
| const prReferences = extractPRReferences(text); | ||
|
|
||
| if (prReferences.length === 0) { | ||
| console.log('No associated PRs found in PR description.'); | ||
| } else { | ||
| for (const prRef of prReferences) { | ||
| // Only process PRs from the same repository | ||
| if (prRef.owner === owner && prRef.repo === repo) { | ||
| await processReferencedPR(prRef, contributors); | ||
| } else { | ||
| console.log( | ||
| `PR #${prRef.prNumber} is from a different repository (${prRef.owner}/${prRef.repo}), skipping...` | ||
| ); | ||
| // Skip processing issue references from external PRs | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async function processReferencedPR(prRef, contributors) { | ||
| // Attempt to fetch the PR to validate its existence | ||
| const referencedPR = await getPRDetails(prRef.prNumber); | ||
| if (!referencedPR) { | ||
| console.log(`PR #${prRef.prNumber} does not exist, skipping...`); | ||
| return; // Skip if PR not found | ||
| } | ||
|
|
||
| const authorLogin = referencedPR.user.login; | ||
|
|
||
| const isContributor = contributors.some((contributor) => contributor.login === authorLogin); | ||
|
|
||
| if (!isContributor) { | ||
| console.log( | ||
| `PR author ${authorLogin} is not a contributor, skipping issue matching for PR #${prRef.prNumber}.` | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| // Clean the referenced PR body | ||
| const refPrBody = cleanText(referencedPR.body); | ||
|
|
||
| // Extract issue references from the referenced PR description | ||
| const refIssueReferences = extractIssueReferences(refPrBody); | ||
|
|
||
| if (refIssueReferences.length === 0) { | ||
| console.log(`No associated issues found in PR #${prRef.prNumber} description.`); | ||
| } else { | ||
| for (const issueRef of refIssueReferences) { | ||
| // Only process issues from the same repository | ||
| if (issueRef.owner === owner && issueRef.repo === repo) { | ||
| const issue = await getIssueDetails( | ||
| issueRef.owner, | ||
| issueRef.repo, | ||
| issueRef.issueNumber | ||
| ); | ||
| if (issue) { | ||
| const { labels: issueLabels, milestone: issueMilestone } = issue; | ||
|
|
||
| if (!issueLabels || issueLabels.length === 0) { | ||
| throw new Error( | ||
| `Associated issue #${issueRef.issueNumber} has no labels.` | ||
| ); | ||
| } | ||
| if (!issueMilestone) { | ||
| throw new Error( | ||
| `Associated issue #${issueRef.issueNumber} has no milestone.` | ||
| ); | ||
| } | ||
| } | ||
| } else { | ||
| console.log( | ||
| `Issue #${issueRef.issueNumber} is from a different repository (${issueRef.owner}/${issueRef.repo}), skipping...` | ||
| ); | ||
| } | ||
| } | ||
| console.log( | ||
| `PR #${prRef.prNumber} and all associated issues have labels and milestones.` | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| async function run() { | ||
| try { | ||
| const pr = await getPRDetails(GITHUB_PR_NUMBER); | ||
| if (!pr) { | ||
| throw new Error(`PR #${GITHUB_PR_NUMBER} not found.`); | ||
| } | ||
|
|
||
| await checkPRLabelsAndMilestone(pr); | ||
|
|
||
| if (isDependabotOrSnykPR(pr)) { | ||
| console.log('Dependabot or snyk PR detected. Skipping issue reference requirement.'); | ||
| return; | ||
| } else { | ||
| const cleanBody = cleanText(pr.body); | ||
| await processIssueReferencesInText(cleanBody); | ||
| } | ||
|
|
||
| const contributors = await getContributors(); | ||
|
|
||
| const cleanBody = cleanText(pr.body); | ||
| await processPRReferencesInText(cleanBody, contributors); | ||
|
|
||
| console.log('All checks completed.'); | ||
| } catch (error) { | ||
| console.error(error.message); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| # Built-in SOLO port forwarding does not work :/ | ||
| # Port forwarding stops shortly after a one-shot Falcon start in GitHub actions. | ||
| # For this reason, we use this script to start port forwarding directly via Bash, | ||
| # instead of relying on the Node.js script. | ||
| # This approach keeps the connection stable and ensures it lasts throughout the tests. | ||
|
|
||
| FORWARDS=( | ||
| "mirror-1-rest|5551" | ||
| "network-node1|50211" | ||
| "relay-1|7546" | ||
| "mirror-1-grpc|5600" | ||
| ) | ||
|
|
||
| ps aux | grep "port-forward" | grep kubectl | awk '{print $2}' | xargs -r kill -9 | ||
| NS="$(kubectl get ns -o name | sed 's|^namespace/||' | grep '^solo' | grep -v '^solo-setup$' | head -n1)" | ||
|
|
||
| listen() { | ||
| local pod="$1" | ||
| local port="$2" | ||
| ( | ||
| while true; do | ||
| if ! ps aux | grep -F kubectl | grep -F port-forward | grep -F " ${port}:${port}" | grep -v grep >/dev/null; then | ||
| kubectl port-forward "$pod" -n "$NS" "${port}:${port}" >/dev/null 2>&1 & | ||
| fi | ||
| sleep 1 | ||
| done | ||
| ) & | ||
| } | ||
|
|
||
| for row in "${FORWARDS[@]}"; do | ||
| IFS='|' read -r include port <<<"$row" | ||
| POD="$(kubectl get pods -A --no-headers | grep -E "$include" | head -n 1 | awk '{print $2}' | head -n1)" | ||
| listen "$POD" "$port" | ||
| done |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.