How to test reuse of a full workflow? #64
-
Hello, Github Actions allows for reusing full workflows: https://docs.github.com/en/actions/using-workflows/reusing-workflows#calling-a-reusable-workflow I want to have reusable workflows in a single repo and complement that with a test setup for this. So far, I haven't been able to create a working setup. I create a mocked Github repo, representing a repo that wants to reuse a workflow, containing a test workflow like this: name: main
on:
push:
jobs:
prerequisites:
uses: <which path here>/.github/workflows/reusable-workflow.yaml
with:
some-input: aValue What I'm struggling with is to come up with the correct path (see Is this supported by this library? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I am assuming you will be testing this setup using If i understood it correctly, you have 2 repositories - 1 which contains the reusable workflow and one which uses the usable workflow? If both of these repositories are setup using mock-github, then you will need a workaround (although I will open a PR in nektos/act to fix this). We essentially have to mimic this workaround - nektos/act#1588 Here is the workaround where both the repositories are setup using mock-github. We essentially fool act into thinking that the repository that contains the reusable workflow is already cloned: reusable.yaml name: main
on:
workflow_call:
inputs:
some-input:
required: false
type: string
jobs:
reusable_workflow_job:
runs-on: ubuntu-latest
steps:
- run: echo ${{ inputs.some-input }} uses-reusable.yaml name: main
on: push
jobs:
prerequisites:
uses: owner/contains-reusable-workflow/.github/workflows/reusable.yaml@main
with:
some-input: aValue reusable.test.ts import { MockGithub } from "@kie/mock-github";
import path from "path";
import { Act } from "@kie/act-js";
let mockGithub: MockGithub;
beforeEach(async () => {
mockGithub = new MockGithub(
{
repo: {
// adding the prefix "act" cause when using XDG_HOME_CACHE, act also adds this. The weird looking name after that is the same as described in https://github.com/nektos/act/issues/1588 workaround
"act/owner-contains-reusable-workflow-.github-workflows-reusable.yaml@main": {
files: [
{
src: path.join(__dirname, "reusable.yaml"),
dest: ".github/workflows/reusable.yaml",
},
],
},
"owner/uses-reusable-workflow": {
files: [
{
src: path.join(__dirname, "uses-reusable.yaml"),
dest: ".github/workflows/uses-reusable.yaml",
},
],
},
},
},
path.join(__dirname, "setup")
);
await mockGithub.setup();
});
afterEach(async () => {
await mockGithub.teardown();
});
test("resuable workflow", async () => {
const act = new Act();
const repoPath = mockGithub.repo.getPath("owner/uses-reusable-workflow");
// setting XDG_CACHE_HOME cause this where act first checks whether the repository exists
process.env["XDG_CACHE_HOME"] = path.join(__dirname, "setup", "repo")
const result = await act
.runJob("prerequisites", {
workflowFile: repoPath,
bind: true,
});
expect(result).toStrictEqual([
{
name: 'Main echo aValue', status: 0, output: 'aValue'
}
])
}); |
Beta Was this translation helpful? Give feedback.
-
Hi just to add on to this, a fix in nektos/act was merged and should be available in the next release (0.2.46): After 0.2.46 is released, I will update act-js and you can simply set the env variable |
Beta Was this translation helpful? Give feedback.
Hi just to add on to this, a fix in nektos/act was merged and should be available in the next release (0.2.46):
After 0.2.46 is released, I will update act-js and you can simply set the env variable
GITHUB_SERVER_URL
to be the path to the parent directory that contains the reusable repositories