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

More GitHub actions support #943

Merged
merged 9 commits into from
Jul 12, 2020
Merged

Conversation

xt0rted
Copy link
Member

@xt0rted xt0rted commented Jun 4, 2020

Checklist:

  • If this PR is a new feature, please provide at least one example link
  • Make sure all of the significant new logic is covered by tests

This builds on the existing support and adds links for local actions in the current repo, as well as actions that have sub actions which are located in a sub folder for the given action.

I had to hard code master for one of the urls because we don't have branch/commit information for it. What we could do is adjust the regex to capture the @v1 value and use that. That should be a tag or commit which both work in the url and would be more accurate.

Local

https://github.com/github/codeql-action/blob/a0d60d5d9e3126a00bed89fd89cc89b7e52a56f2/.github/workflows/codeql.yml#L24-L28

Sub folders

https://github.com/twbs/bootstrap/blob/5faf41eb4837491fa8193910c5816efadb4dbc5a/.github/workflows/codeql.yml#L22-L25

@xt0rted xt0rted requested a review from stefanbuck June 4, 2020 08:06
Comment on lines +13 to +15
const [, org, repo, , sha] = path.split('/');

return `{BASE_URL}/${join(org, repo, 'tree', sha, target)}`;
Copy link
Member Author

Choose a reason for hiding this comment

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

I have another PR I'm working on for Dart or C/C++ that does this same thing. I'll make sure to move this out to a helper when I get back to it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I used join() for these because that's how it was done here and it seemed a little cleaner. Do you have a preference to how these are built?

return `{BASE_URL}${join(dirname(path), target)}`;

Copy link
Member

Choose a reason for hiding this comment

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

I don't mind, but I agree, your solution is more explicit.

# @OctoLinkerResolve(https://github.com/github/codeql-action/tree/master/init)
- uses: github/codeql-action/init@v1
# @OctoLinkerResolve(https://github.com/OctoLinker/OctoLinker)
- uses: ./
Copy link
Member Author

Choose a reason for hiding this comment

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

For some reason this test failed but it works correctly in the browser.

✕ resolves - uses: ./ to https://github.com/OctoLinker/OctoLinker (5001 ms)

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

How do you run the e2e tests locally? I adjusted generate-fixtures-json.js to point to my fork & branch, but I keep getting the following output when trying to run them:

❯ node "c:/dev/xt0rted/OctoLinker/node_modules/jest/bin/jest.js" "c:/dev/xt0rted/OctoLinker/e2e/automated.test.js" -t "End to End tests single blob"
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In C:\dev\xt0rted\OctoLinker
  198 files checked.
  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 37 matches
  testPathIgnorePatterns: C:\\dev\\xt0rted\\OctoLinker\\e2e\\ - 186 matches
  testRegex:  - 0 matches
Pattern: c:\\dev\\xt0rted\\OctoLinker\\e2e\\automated.test.js - 0 matches

The fixtures.json was created, but the tests in automated.test.js don't run.

Copy link
Member

Choose a reason for hiding this comment

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

There is a special jest config for e2e tests --config=e2e/jest-e2e.config.js which is used when running yarn e2e

@xt0rted xt0rted changed the title GitHub actions More GitHub actions support Jun 4, 2020
@@ -18,11 +18,14 @@ const async = require('async');
// ]

let username;
let sha = 'HEAD';
Copy link
Member

Choose a reason for hiding this comment

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

This won't work when running yarn e2e local. I resist to call out the git binary to get the latest sha, because this doesn't work under all conditions for example the latest commit isn't pushed yet.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should consider not adding tests for relative links in workflow files. What do you think @xt0rted ?

Copy link
Member Author

@xt0rted xt0rted Jul 11, 2020

Choose a reason for hiding this comment

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

I'm ok with that. Should I remove that test and rebase this or do you want to merge it with the fixup commits?

If the tests weren't generated we could add a check for this one so it only ran if the github_actions env var was true.

Copy link
Member

Choose a reason for hiding this comment

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

I think using an env var doesn't solve the actual issue, because the sha will be different all the time, right? Also this would fail when running on a fork right? Let's just remove that test and get this merged.

Copy link
Member Author

Choose a reason for hiding this comment

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

When these run they pull whatever is in the current branch, so the sha will change on each run. If the test only ran when GITHUB_ACTION was true then we'd also be able to get the sha from GITHUB_SHA, but that won't work with the current test setup. Maybe in the future, but not now.

Copy link
Member

Choose a reason for hiding this comment

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

A while ago I came across the fact that the env var GITHUB_SHA is different depending on whether your workflow runs on push or pull_request events.

Pull request event: Last merge commit on the GITHUB_REF branch
Push event: Commit pushed, unless deleting a branch (when it's the default branch)

https://help.github.com/en/actions/reference/events-that-trigger-workflows


if (folder.length) {
return [
`{BASE_URL}/${join(org, repo, 'tree', 'main', ...folder)}`,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is because GitHub is starting to rename their default branches from master to main and I think this is supposed to become the site's default for new repos soon.

Copy link
Member

Choose a reason for hiding this comment

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

Do you mind if we address this separately? There are a few places where master is hardcoded and I think this needs some additional thoughts

Copy link
Member Author

Choose a reason for hiding this comment

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

Without this the test won't pass because the github/codeql-action repo uses main now.

Copy link
Member

Choose a reason for hiding this comment

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

😄 Ahh I see, thanks for the hint.

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened #974 for this.

@xt0rted
Copy link
Member Author

xt0rted commented Jul 12, 2020

This should be good now.

@stefanbuck stefanbuck merged commit 9e606a9 into OctoLinker:master Jul 12, 2020
@xt0rted xt0rted deleted the github-actions branch July 12, 2020 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants