Skip to content

Commit

Permalink
Merge branch 'develop' into BCI-3730-remove-minconfirmations-evm-txm
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhen1997 authored Aug 8, 2024
2 parents 67a5f8a + ebd45ce commit 7091ba8
Show file tree
Hide file tree
Showing 29 changed files with 518 additions and 282 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-crabs-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#added Add Astar TerminallyUnderpriced error mapping
5 changes: 5 additions & 0 deletions .changeset/sweet-pumas-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

#bugfix Addresses 2 minor issues with the pruning of LogPoller's db tables: logs not matching any filter will now be pruned, and rows deleted are now properly reported for observability
77 changes: 77 additions & 0 deletions .github/scripts/jira/enforce-jira-issue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import * as core from "@actions/core";
import jira from "jira.js";
import { createJiraClient, parseIssueNumberFrom } from "./lib";

async function doesIssueExist(
client: jira.Version3Client,
issueNumber: string,
dryRun: boolean
) {
const payload = {
issueIdOrKey: issueNumber,
};

if (dryRun) {
core.info("Dry run enabled, skipping JIRA issue enforcement");
return true;
}

try {
/**
* The issue is identified by its ID or key, however, if the identifier doesn't match an issue, a case-insensitive search and check for moved issues is performed.
* If a matching issue is found its details are returned, a 302 or other redirect is not returned. The issue key returned in the response is the key of the issue found.
*/
const issue = await client.issues.getIssue(payload);
core.debug(
`JIRA issue id:${issue.id} key: ${issue.key} found while querying for ${issueNumber}`
);
if (issue.key !== issueNumber) {
core.error(
`JIRA issue key ${issueNumber} not found, but found issue key ${issue.key} instead. This can happen if the identifier doesn't match an issue, in which case a case-insensitive search and check for moved issues is performed. Make sure the issue key is correct.`
);
return false;
}

return true;
} catch (e) {
core.debug(e as any);
return false;
}
}

async function main() {
const prTitle = process.env.PR_TITLE;
const commitMessage = process.env.COMMIT_MESSAGE;
const branchName = process.env.BRANCH_NAME;
const dryRun = !!process.env.DRY_RUN;
const client = createJiraClient();

// Checks for the Jira issue number and exit if it can't find it
const issueNumber = parseIssueNumberFrom(prTitle, commitMessage, branchName);
if (!issueNumber) {
const msg =
"No JIRA issue number found in PR title, commit message, or branch name. This pull request must be associated with a JIRA issue.";

core.setFailed(msg);
return;
}

const exists = await doesIssueExist(client, issueNumber, dryRun);
if (!exists) {
core.setFailed(`JIRA issue ${issueNumber} not found, this pull request must be associated with a JIRA issue.`);
return;
}
}

async function run() {
try {
await main();
} catch (error) {
if (error instanceof Error) {
return core.setFailed(error.message);
}
core.setFailed(error as any);
}
}

run();
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, describe, it } from "vitest";
import { parseIssueNumberFrom, tagsToLabels } from "./update-jira-issue";
import { parseIssueNumberFrom, tagsToLabels } from "./lib";

describe("parseIssueNumberFrom", () => {
it("should return the first JIRA issue number found", () => {
Expand All @@ -18,6 +18,17 @@ describe("parseIssueNumberFrom", () => {
expect(r).to.equal("CORE-123");
});

it("works with multiline commit bodies", () => {
const r = parseIssueNumberFrom(
`This is a multiline commit body
CORE-1011`,
"CORE-456",
"CORE-789"
);
expect(r).to.equal("CORE-1011");
});

it("should return undefined if no JIRA issue number is found", () => {
const result = parseIssueNumberFrom("No issue number");
expect(result).to.be.undefined;
Expand Down
63 changes: 63 additions & 0 deletions .github/scripts/jira/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

import * as core from '@actions/core'
import * as jira from 'jira.js'

/**
* Given a list of strings, this function will return the first JIRA issue number it finds.
*
* @example parseIssueNumberFrom("CORE-123", "CORE-456", "CORE-789") => "CORE-123"
* @example parseIssueNumberFrom("2f3df5gf", "chore/test-RE-78-branch", "RE-78 Create new test branches") => "RE-78"
*/
export function parseIssueNumberFrom(
...inputs: (string | undefined)[]
): string | undefined {
function parse(str?: string) {
const jiraIssueRegex = /[A-Z]{2,}-\d+/;

return str?.toUpperCase().match(jiraIssueRegex)?.[0];
}

core.debug(`Parsing issue number from: ${inputs.join(", ")}`);
const parsed: string[] = inputs.map(parse).filter((x) => x !== undefined);
core.debug(`Found issue number: ${parsed[0]}`);

return parsed[0];
}

/**
* Converts an array of tags to an array of labels.
*
* A label is a string that is formatted as `core-release/{tag}`, with the leading `v` removed from the tag.
*
* @example tagsToLabels(["v1.0.0", "v1.1.0"]) => [{ add: "core-release/1.0.0" }, { add: "core-release/1.1.0" }]
*/
export function tagsToLabels(tags: string[]) {
const labelPrefix = "core-release";

return tags.map((t) => ({
add: `${labelPrefix}/${t.substring(1)}`,
}));
}

export function createJiraClient() {
const jiraHost = process.env.JIRA_HOST;
const jiraUserName = process.env.JIRA_USERNAME;
const jiraApiToken = process.env.JIRA_API_TOKEN;

if (!jiraHost || !jiraUserName || !jiraApiToken) {
core.setFailed(
"Error: Missing required environment variables: JIRA_HOST and JIRA_USERNAME and JIRA_API_TOKEN."
);
process.exit(1);
}

return new jira.Version3Client({
host: jiraHost,
authentication: {
basic: {
email: jiraUserName,
apiToken: jiraApiToken,
},
},
});
}
4 changes: 3 additions & 1 deletion .github/scripts/jira/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"pnpm": ">=9"
},
"scripts": {
"start": "tsx update-jira-issue.ts"
"issue:update": "tsx update-jira-issue.ts",
"issue:enforce": "tsx enforce-jira-issue.ts",
"test": "vitest"
},
"dependencies": {
"@actions/core": "^1.10.1",
Expand Down
59 changes: 1 addition & 58 deletions .github/scripts/jira/update-jira-issue.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,6 @@
import * as core from "@actions/core";
import jira from "jira.js";

/**
* Given a list of strings, this function will return the first JIRA issue number it finds.
*
* @example parseIssueNumberFrom("CORE-123", "CORE-456", "CORE-789") => "CORE-123"
* @example parseIssueNumberFrom("2f3df5gf", "chore/test-RE-78-branch", "RE-78 Create new test branches") => "RE-78"
*/
export function parseIssueNumberFrom(
...inputs: (string | undefined)[]
): string | undefined {
function parse(str?: string) {
const jiraIssueRegex = /[A-Z]{2,}-\d+/;

return str?.toUpperCase().match(jiraIssueRegex)?.[0];
}

const parsed: string[] = inputs.map(parse).filter((x) => x !== undefined);

return parsed[0];
}

/**
* Converts an array of tags to an array of labels.
*
* A label is a string that is formatted as `core-release/{tag}`, with the leading `v` removed from the tag.
*
* @example tagsToLabels(["v1.0.0", "v1.1.0"]) => [{ add: "core-release/1.0.0" }, { add: "core-release/1.1.0" }]
*/
export function tagsToLabels(tags: string[]) {
const labelPrefix = "core-release";

return tags.map((t) => ({
add: `${labelPrefix}/${t.substring(1)}`,
}));
}
import { tagsToLabels, createJiraClient, parseIssueNumberFrom } from "./lib";

function updateJiraIssue(
client: jira.Version3Client,
Expand Down Expand Up @@ -64,29 +30,6 @@ function updateJiraIssue(
return client.issues.editIssue(payload);
}

function createJiraClient() {
const jiraHost = process.env.JIRA_HOST;
const jiraUserName = process.env.JIRA_USERNAME;
const jiraApiToken = process.env.JIRA_API_TOKEN;

if (!jiraHost || !jiraUserName || !jiraApiToken) {
core.setFailed(
"Error: Missing required environment variables: JIRA_HOST and JIRA_USERNAME and JIRA_API_TOKEN."
);
process.exit(1);
}

return new jira.Version3Client({
host: jiraHost,
authentication: {
basic: {
email: jiraUserName,
apiToken: jiraApiToken,
},
},
});
}

async function main() {
const prTitle = process.env.PR_TITLE;
const commitMessage = process.env.COMMIT_MESSAGE;
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/changeset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
working-directory: ./.github/scripts/jira
run: |
echo "COMMIT_MESSAGE=$(git log -1 --pretty=format:'%s')" >> $GITHUB_ENV
pnpm install && pnpm start
pnpm install && pnpm issue:update
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JIRA_HOST: ${{ secrets.JIRA_HOST }}
Expand Down
28 changes: 14 additions & 14 deletions .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,37 +341,37 @@ jobs:
- name: Download all workflow run artifacts
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4

- name: Set SonarQube Report Paths
id: sonarqube_report_paths
- name: Check and Set SonarQube Report Paths
shell: bash
run: |
echo "sonarqube_tests_report_paths=$(find go_core_tests_logs -name output.txt | paste -sd "," -)" >> $GITHUB_OUTPUT
echo "sonarqube_coverage_report_paths=$(find go_core_tests_logs -name coverage.txt | paste -sd "," -)" >> $GITHUB_OUTPUT
echo "sonarqube_lint_report_paths=$(find golangci-lint-report -name golangci-lint-report.xml | paste -sd "," -)" >> $GITHUB_OUTPUT
sonarqube_tests_report_paths=$(find go_core_tests_logs -name output.txt | paste -sd "," -)
sonarqube_coverage_report_paths=$(find go_core_tests_logs -name coverage.txt | paste -sd "," -)
sonarqube_lint_report_paths=$(find golangci-lint-report -name golangci-lint-report.xml | paste -sd "," -)
- name: Check SonarQube Report Paths
id: check_sonarqube_paths
run: |
ARGS=""
if [[ -z "${{ steps.sonarqube_report_paths.outputs.sonarqube_tests_report_paths }}" ]]; then
if [[ -z "$sonarqube_tests_report_paths" ]]; then
echo "::warning::No test report paths found, will not pass to sonarqube"
else
ARGS="$ARGS -Dsonar.go.tests.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_tests_report_paths }}"
echo "Found test report paths: $sonarqube_tests_report_paths"
ARGS="$ARGS -Dsonar.go.tests.reportPaths=$sonarqube_tests_report_paths"
fi
if [[ -z "${{ steps.sonarqube_report_paths.outputs.sonarqube_coverage_report_paths }}" ]]; then
if [[ -z "$sonarqube_coverage_report_paths" ]]; then
echo "::warning::No coverage report paths found, will not pass to sonarqube"
else
ARGS="$ARGS -Dsonar.go.coverage.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_coverage_report_paths }}"
echo "Found coverage report paths: $sonarqube_coverage_report_paths"
ARGS="$ARGS -Dsonar.go.coverage.reportPaths=$sonarqube_coverage_report_paths"
fi
if [[ -z "${{ steps.sonarqube_report_paths.outputs.sonarqube_lint_report_paths }}" ]]; then
if [[ -z "$sonarqube_lint_report_paths" ]]; then
echo "::warning::No lint report paths found, will not pass to sonarqube"
else
ARGS="$ARGS -Dsonar.go.golangci-lint.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_lint_report_paths }}"
echo "Found lint report paths: $sonarqube_lint_report_paths"
ARGS="$ARGS -Dsonar.go.golangci-lint.reportPaths=$sonarqube_lint_report_paths"
fi
echo "Final SONARQUBE_ARGS: $ARGS"
echo "SONARQUBE_ARGS=$ARGS" >> $GITHUB_ENV
- name: SonarQube Scan
Expand Down
Loading

0 comments on commit 7091ba8

Please sign in to comment.