Skip to content
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

@W-11831625@: Ported testing jobs from CircleCI to Github Actions. #843

Merged
merged 6 commits into from
Nov 3, 2022

Conversation

jfeingold35
Copy link
Collaborator

No description provided.

@@ -0,0 +1,205 @@
name: run-tests
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs all the tests, and it has parameters to let us make matrices for node versions. So we could easily create a daily smoke test job that invokes this one the same way the validate_pr one does.

@@ -74,6 +74,7 @@
"@types/tmp": "^0.2.3",
"@types/uuid": "^8.3.4",
"chai": "^4",
"cross-env": "^7.0.3",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -135,6 +136,7 @@
"postpack": "rm -f oclif.manifest.json",
"lint": "eslint ./src --ext .ts",
"test": "./gradlew test jacocoTestCoverageVerification && nyc mocha --timeout 10000 --retries 5 \"./test/**/*.test.ts\"",
"test-quiet": "cross-env SFGE_LOGGING=false ./gradlew test jacocoTestCoverageVerification && nyc mocha --timeout 10000 --retries 5 \"./test/**/*.test.ts\"",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the new variable, we can disable SFGE's internal logging, which is important to avoid overflowing the logs in Github Action.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see why this is important. Though when we have failures, the logs would surely help with troubleshooting.
How about writing the output to a file instead of letting it overflow to the console window?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My assumption is that, for a test failure, you'd check the artifact to see what the failures were, and then run those specific tests locally to reproduce.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose my discomfort comes from situations where the issue doesn't repro locally. Can we set a higher threshold for logging rather than completely turning it off?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll see how doable that is and get back to you.

# Upload the test results and coverage information as artifacts.
- name: Upload node test artifacts
if: ${{ always() }}
uses: actions/upload-artifact@v3
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test results get saved as artifacts, so we can view the specifics of the run by downloading and unzipping those.

name: unit-test-dist
path: ./dist
# Run the unit tests. Use the -quiet variant so SFGE logs don't blow up the console.
- name: Run Tests
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the tests fail, these jobs exit with a non-zero code, indicating a failure.

name: validate-pr
on:
pull_request:
types: [edited, opened, reopened, synchronized]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runs on basically any PR action.

// Show log4j output during tests
showStandardStreams = true
// Show log4j output during tests, unless env-var to disable them is set.
showStandardStreams = (System.getenv("SFGE_LOGGING") != "false")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the part where the new env-var is used.

const results = (await RuleResultRecombinator.recombineAndReformatResults(retireJsVerboseViolations, OUTPUT_FORMAT.HTML, new Set(['retire-js']), true)).results as string;
const violationString = results.split("const violations = [")[1].split("];\n")[0];
const violationString = results.split("const violations = [")[1].split("];")[0];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was failing in Windows, on Powershell. I believe the problem was that because Windows uses \r\n instead of \n, the split was failing.

@@ -7,7 +7,7 @@ import { ENGINE, LANGUAGE } from '../../../src/Constants';
import { Rule, RuleGroup } from '../../../src/types';
import LocalCatalog from '../../../src/lib/services/LocalCatalog';
import { expect } from 'chai';
import {Controller} from '../../../lib/Controller';
import {Controller} from '../../../src/Controller';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import path was wrong.

@@ -0,0 +1,203 @@
name: run-tests
on:
workflow_call:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workflow_call lets us reuse this across all of the places where we might want to run tests, which is pretty helpful.


jobs:
# Step 1: Verify that the tag we're trying to release is a valid candidate for publishing.
verify-candidate-tag:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty closely copied from validate-candidate-branch.sh, just split into a job and converted to use tags.

PACKAGE_VERSION=v`cat package.json | jq '.version' | xargs`
[[ ${TAG} == ${PACKAGE_VERSION} ]] || (echo "Tag name must match package.json version, prefixed by lowercase v" && exit 1)
# Step 2: Publish the tag as a release candidate.
publish-rc:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This job is analogous to an example job provided by the CLI team, with the only significant difference being that we use the latest-rc tag, whereas they use latest.

@jfeingold35 jfeingold35 marked this pull request as ready for review November 2, 2022 19:45
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11' # For now, Java version is hardcoded. It could be changed to a matrix in the future.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be 8?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this should be 11. But we could matrixify it so it uses 8 and 11.

needs: build-dependencies
steps:
# Check out the code.
- uses: actions/checkout@v2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading around, I see there's a actions/checkout@v3 as well. Is a specific reason to use v2 instead of v3?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed a combination of v3 in the release workflow and v2 in the test workflow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I'll switch to v3 throughout.

- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11' # For now, Java version is hardcoded. It could be changed to a matrix in the future.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above - should this be 8?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

# If the path starts with C:, we need to rip that off (needed for Windows).
ADJUSTED_TARBALL_PATH=`[[ $RAW_TARBALL_PATH = C* ]] && echo $RAW_TARBALL_PATH | cut -d':' -f 2 || echo $RAW_TARBALL_PATH`
# Pipe in a `y` to simulate agreeing to install an unsigned package. Use a URI of the file's full path.
echo y | sfdx plugins:install "file://${ADJUSTED_TARBALL_PATH}/${TARBALL_NAME}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can windows fail with the / in the path instead of \?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, for this block, how about gating with an "if os == windows" check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never saw it fail, so I think it should be fine without.

- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11' # For now, Java version is hardcoded.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be 8?

Copy link
Collaborator Author

@jfeingold35 jfeingold35 Nov 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. Good catch.
Edit: Actually, no I think it should be 11. Because this is the RC test, not the building for publishing. We want to test with v11, right?
(Alternatively, we could matrixify this and test with both 8 and 11. Thoughts?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see why 11 then. Agree that this doesn't have to be 8. I like the idea of testing with multiple java versions. Especially to keep up with the later versions. Would it be easy to include now while we are here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be too hard.

Copy link
Contributor

@rmohan20 rmohan20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So many details covered, this looks great! I had a few minor questions.

@@ -13,7 +13,7 @@
},
"dependencies": {
"@actions/core": "^1.2.4",
"@actions/github": "^4.0.0"
"@actions/github": "^5.0.0"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incrementation was necessary to bypass this issue: octokit/plugin-rest-endpoint-methods.js#172

const title = pullRequest.title;
const baseBranch = pullRequest.base.ref;
if (verifyPRTitleForBugId(title) && verifyPRTitleForBadTitle(title) && verifyPRTitleForBaseBranch(title, baseBranch)) {
const title = pullRequest.title as string;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linting fixes.

@@ -31,14 +30,6 @@ describe("Positive Tests", () => {
it("Title does not start with invalid tokens d/W or r/W", () => {
expect(verifyPRTitleForBadTitle("@W-12345678")).to.equal(true);
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed unneeded tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants