Skip to content

Commit

Permalink
More GitHub actions support (#943)
Browse files Browse the repository at this point in the history
* Support local actions

* Support actions in subfolders

* Generate e2e fixture which includes current sha

* fixup! Generate e2e fixture which includes current sha

* fixup! Generate e2e fixture which includes current sha

* fixup! Generate e2e fixture which includes current sha

* fixup! Generate e2e fixture which includes current sha

* Remove relative action test

* Check both main and master branches

Co-authored-by: Stefan Buck <[email protected]>
  • Loading branch information
xt0rted and stefanbuck committed Jul 12, 2020
1 parent 392bd8c commit 9e606a9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions e2e/fixtures/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ jobs:
- uses: actions/setup-node
# @OctoLinkerResolve(https://github.com/actions/upload-artifact)
- uses: actions/upload-artifact@master
# @OctoLinkerResolve(https://github.com/github/codeql-action/tree/main/init)
- uses: github/codeql-action/init@v1
11 changes: 10 additions & 1 deletion e2e/generate-fixtures-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ const async = require('async');
// ]

let username;
let sha = 'HEAD';

if (process.env.GITHUB_EVENT_PATH) {
const json = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH));
if (json && json.pull_request) {
username = json.pull_request.head.user.login;
// eslint-disable-next-line prefer-destructuring
sha = json.pull_request.head.sha;
}
}

Expand All @@ -31,6 +34,7 @@ const branch = process.env.GITHUB_HEAD_REF || 'master';
const fixturesRoot = `https://github.com/${user}/OctoLinker/blob/${branch}/e2e`;

console.log('Fixtures root:', fixturesRoot); // eslint-disable-line no-console
console.log('Fixtures sha:', sha); // eslint-disable-line no-console

async function readContent(files) {
const readFile = util.promisify(fs.readFile);
Expand Down Expand Up @@ -61,7 +65,12 @@ function findTests(contents) {

const targetUrl = line
.match(/@OctoLinkerResolve(Above)?\((.*?)\)/)[2]
.replace('<root>', '');
.replace('<root>', '')
.replace('<sha>', sha)
.replace(
'https://github.com/OctoLinker/OctoLinker/tree/',
`https://github.com/${user}/OctoLinker/tree/`,
);

const filePath = file.replace(__dirname, '');

Expand Down
16 changes: 16 additions & 0 deletions packages/plugin-github-actions/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { join } from 'path';
import { GITHUB_ACTIONS } from '@octolinker/helper-grammar-regex-collection';

export default {
Expand All @@ -8,6 +9,21 @@ export default {
return '';
}

if (target.startsWith('.')) {
const [, org, repo, , sha] = path.split('/');

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

const [org, repo, ...folder] = target.split('/');

if (folder.length) {
return [
`{BASE_URL}/${join(org, repo, 'tree', 'main', ...folder)}`,
`{BASE_URL}/${join(org, repo, 'tree', 'master', ...folder)}`,
];
}

return `{BASE_URL}/${target}`;
},

Expand Down

0 comments on commit 9e606a9

Please sign in to comment.