Skip to content

Support github actions as service #136

Description

@TheSnoozer

Similar to all other services (e.g. the jenkins service), there should be a service that supports github actions.

Environment variables are documented in https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables#default-environment-variables

Untested:

public class GithubAction extends AbstractServiceSetup {

    public static final String GITHUB_ACTION_NAME = "githubaction";
    public static final String GITHUB_ACTIONS = "GITHUB_ACTIONS";
    public static final String GITHUB_ACTION_BUILD_NUMBER = "GITHUB_ACTION";
    public static final String GITHUB_ACTION_BUILD_URL = "GITHUB_REPOSITORY";
    public static final String GITHUB_ACTION_BRANCH = "GITHUB_REF";
    public static final String GITHUB_ACTION_COMMIT = "GITHUB_SHA";
    
    public Jenkins(final Map<String, String> env) {
        super(env);
    }

    @Override
    public boolean isSelected() {
        return (getProperty(GITHUB_ACTIONS) != null);
    }
    
    @Override
    public String getName() {
        return GITHUB_ACTION_NAME;
    }
    
    @Override
    public String getBuildNumber() {
        return getProperty(GITHUB_ACTION_BUILD_NUMBER);
    }
    
    @Override
    public String getBuildUrl() {
        // TODO: do we need https://github.com here?
        return getProperty(GITHUB_ACTION_BUILD_URL);
    }
    
    @Override
    public String getBranch() {
        // TODO: this looks like "refs/heads/feature-branch-1" and might be empty - does this mean null?
        return getProperty(GITHUB_ACTION_BRANCH);
    }
    
    @Override
    public Properties getEnvironment() {
        Properties environment = new Properties();
        addProperty(environment, "github_action_build_num", getBuildNumber());
        addProperty(environment, "github_action_build_url", getBuildUrl());
        addProperty(environment, "branch", getBranch());
        addProperty(environment, "commit_sha", getProperty(GITHUB_ACTION_COMMIT));
        return environment;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions