ros-tooling/action-ros-ci

Input for git reference to checkout

Closed this issue · 3 comments

Description

The action always checks out the branch it was triggered from. A cron event to trigger an action only works from the default branch, so I have not found a way to run daily jobs for multiple branches. With a ref input it would be possible to have an action for a specific branch in the default branch.

Completion Criteria

  • ref input added to specify git reference

Testing Notes / Suggestions

  • The specified git reference is actually checked out

This sounds like a great feature. I'm actually going to be needing this soon, so I'll probably try to implement this, unless you wanted to do it.

Ran into this issue on a project which triggers CI daily on all the supported branches.
I'm not 💯 familiar with ts or actions but looks like something is needed here:

https://github.com/ros-tooling/action-ros-ci/blob/master/src/action-ros-ci.ts#L553-L574

        // The repo file for the repository needs to be generated on-the-fly to
        // incorporate the custom repository URL and branch name, when a PR is
        // being built.
        let repoFullName = process.env.GITHUB_REPOSITORY as string;
        if (github.context.payload.pull_request) {
                repoFullName = github.context.payload.pull_request.head.repo.full_name;
        }
        const headRef = process.env.GITHUB_HEAD_REF as string;
        const commitRef = headRef || github.context.sha;
        const repoFilePath = path.join(rosWorkspaceDir, "package.repo");
        // Add a random string prefix to avoid naming collisions when checking out the test repository
        const randomStringPrefix = Math.random().toString(36).substring(2, 15);
        const repoFileContent = `repositories:
  ${randomStringPrefix}/${repo["repo"]}:
    type: git
    url: 'https://github.com/${repoFullName}.git'
    version: '${commitRef}'`;
        fs.writeFileSync(repoFilePath, repoFileContent);
        await execShellCommand(
                ["vcs import --force --recursive src/ < package.repo"],
                options
        );

Indeed, that is the relevant part.

I haven't had time to implement this yet, so feel free to give it a shot.