How to use @actions/core - 10 common examples

To help you get started, we’ve selected a few @actions/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ReactiveCircus / android-emulator-runner / src / main.ts View on Github external
checkApiLevel(apiLevelInput);
    const apiLevel = Number(apiLevelInput);
    console.log(`API level: ${apiLevel}`);

    // target of the system image
    const target = core.getInput('target');
    checkTarget(target);
    console.log(`target: ${target}`);

    // CPU architecture of the system image
    const arch = core.getInput('arch');
    checkArch(arch);
    console.log(`CPU architecture: ${arch}`);

    // Hardware profile used for creating the AVD
    const profile = core.getInput('profile');
    console.log(`Hardware profile: ${profile}`);

    // emulator options
    const emulatorOptions = core.getInput('emulator-options').trim();
    console.log(`emulator options: ${emulatorOptions}`);

    // disable animations
    const disableAnimationsInput = core.getInput('disable-animations');
    checkDisableAnimations(disableAnimationsInput);
    const disableAnimations = disableAnimationsInput === 'true';
    console.log(`disable animations: ${disableAnimations}`);

    // custom script to run
    const scriptInput = core.getInput('script', { required: true });
    const scripts = parseScript(scriptInput);
    console.log(`Script:`);
github TryGhost / action-deploy-theme / index.js View on Github external
(async function main() {
    try {
        const url = core.getInput('api-url');
        const api = new GhostAdminApi({
            url,
            key: core.getInput('api-key'),
            version: 'canary'
        });

        const basePath = process.env.GITHUB_WORKSPACE;
        const pkgPath = path.join(process.env.GITHUB_WORKSPACE, 'package.json');
        const themeName = core.getInput('theme-name') || require(pkgPath).name;
        const themeZip = `${themeName}.zip`;
        const zipPath = path.join(basePath, themeZip);
        const exclude = core.getInput('exclude') || '';

        // Create a zip
        await exec.exec(`zip -r ${themeZip} . -x *.git* *.zip yarn* npm* *routes.yaml *redirects.yaml *redirects.json ${exclude}`, [], {cwd: basePath});

        // Deploy it to the configured site
        await api.themes.upload({file: zipPath});
        console.log(`${themeZip} successfully uploaded.`);
github codfish / semantic-release-action / entrypoint.js View on Github external
async function run() {
  const branch = core.getInput('branch', { required: false }) || 'master';
  const result = await semanticRelease({ branch });

  if (!result) {
    core.debug('No release published');

    // set outputs
    core.exportVariable('NEW_RELEASE_PUBLISHED', 'false');
    core.setOutput('new-release-published', 'false');
    return;
  }

  const { lastRelease, nextRelease, commits } = result;

  core.debug(
    `Published ${nextRelease.type} release version ${nextRelease.version} containing ${commits.length} commits.`,
  );

  if (lastRelease.version) {
    core.debug(`The last release was "${lastRelease.version}".`);
  }

  // outputs
  const { version } = nextRelease;
  const major = version.split('.')[0];
  const minor = version.split('.')[1];
  const patch = version.split('.')[2];

  // set outputs
  core.exportVariable('NEW_RELEASE_PUBLISHED', 'true');
  core.exportVariable('RELEASE_VERSION', version);
github mathieudutour / github-tag-action / src / main.ts View on Github external
async function run() {
  try {
    // @ts-ignore
    const bump: ReleaseType = core.getInput("default_bump");
    const tagPrefix = core.getInput("tag_prefix");
    const releaseBranches = core.getInput("release_branches");

    const { GITHUB_REF, GITHUB_SHA } = process.env;

    if (!GITHUB_REF) {
      core.setFailed("Missing GITHUB_REF");
      return;
    }

    if (!GITHUB_SHA) {
      core.setFailed("Missing GITHUB_SHA");
      return;
    }

    const preRelease = releaseBranches
      .split(",")
      .every(branch => !GITHUB_REF.replace("refs/heads/", "").match(branch));

    const hasTag = !!(await exec("git tag")).stdout.trim();
    let tag = "";

    if (hasTag) {
      const previousTagSha = (
        await exec("git rev-list --tags --max-count=1")
      ).stdout.trim();
      tag = (await exec(`git describe --tags ${previousTagSha}`)).stdout.trim();
github mooyoul / tslint-actions / index.ts View on Github external
})().catch((e) => {
  console.error(e.stack); // tslint:disable-line
  core.setFailed(e.message);
});
github codfish / semantic-release-action / entrypoint.js View on Github external
if (lastRelease.version) {
    core.debug(`The last release was "${lastRelease.version}".`);
  }

  // outputs
  const { version } = nextRelease;
  const major = version.split('.')[0];
  const minor = version.split('.')[1];
  const patch = version.split('.')[2];

  // set outputs
  core.exportVariable('NEW_RELEASE_PUBLISHED', 'true');
  core.exportVariable('RELEASE_VERSION', version);
  core.exportVariable('RELEASE_MAJOR', major);
  core.exportVariable('RELEASE_MINOR', minor);
  core.exportVariable('RELEASE_PATCH', patch);
  core.setOutput('new-release-published', 'true');
  core.setOutput('release-version', version);
  core.setOutput('release-major', major);
  core.setOutput('release-minor', minor);
  core.setOutput('release-patch', patch);
}
github codfish / semantic-release-action / entrypoint.js View on Github external
core.debug(`The last release was "${lastRelease.version}".`);
  }

  // outputs
  const { version } = nextRelease;
  const major = version.split('.')[0];
  const minor = version.split('.')[1];
  const patch = version.split('.')[2];

  // set outputs
  core.exportVariable('NEW_RELEASE_PUBLISHED', 'true');
  core.exportVariable('RELEASE_VERSION', version);
  core.exportVariable('RELEASE_MAJOR', major);
  core.exportVariable('RELEASE_MINOR', minor);
  core.exportVariable('RELEASE_PATCH', patch);
  core.setOutput('new-release-published', 'true');
  core.setOutput('release-version', version);
  core.setOutput('release-major', major);
  core.setOutput('release-minor', minor);
  core.setOutput('release-patch', patch);
}
github peter-evans / slash-command-dispatch / src / index.js View on Github external
commentWords,
        cmd.named_args
      );
      core.debug(
        `Slash command payload: ${inspect(clientPayload.slash_command)}`
      );
      // Dispatch the command
      const dispatchRepo = cmd.repository.split("/");
      const eventType = cmd.command + cmd.event_type_suffix;
      await octokit.repos.createDispatchEvent({
        owner: dispatchRepo[0],
        repo: dispatchRepo[1],
        event_type: eventType,
        client_payload: clientPayload
      });
      core.info(
        `Command '${cmd.command}' dispatched to '${cmd.repository}' ` +
          `with event type '${eventType}'.`
      );
    }

    // Add the "rocket" reaction to the comment
    if (inputs.reactions)
      await addReaction(
        reactionOctokit,
        github.context.repo,
        commentId,
        "rocket"
      );
  } catch (error) {
    core.debug(inspect(error));
    core.setFailed(error.message);
github peter-evans / slash-command-dispatch / src / index.js View on Github external
if (commentBody.charAt(0) != "/" || commentBody.length < 2) {
      core.info("Comment is not a valid slash command.");
      return;
    }

    // Split the comment into "words"
    const commentWords = commentBody.slice(1).split(" ");
    core.debug(`Comment words: ${inspect(commentWords)}`);

    // Check if the command is registered for dispatch
    var configMatches = config.filter(function(cmd) {
      return cmd.command == commentWords[0];
    });
    core.debug(`Config matches on 'command': ${inspect(configMatches)}`);
    if (configMatches.length == 0) {
      core.info(`Command '${commentWords[0]}' is not registered for dispatch.`);
      return;
    }

    // Filter matching commands by issue type
    const isPullRequest = "pull_request" in github.context.payload.issue;
    configMatches = configMatches.filter(function(cmd) {
      return (
        cmd.issue_type == "both" ||
        (cmd.issue_type == "issue" && !isPullRequest) ||
        (cmd.issue_type == "pull-request" && isPullRequest)
      );
    });
    core.debug(`Config matches on 'issue_type': ${inspect(configMatches)}`);
    if (configMatches.length == 0) {
      const issueType = isPullRequest ? "pull request" : "issue";
      core.info(
github treosh / lighthouse-ci-action / src / input.js View on Github external
}
  }

  // Get and interpolate URLs
  const urls = interpolateProcessIntoURLs(getList('urls'))

  // Make sure we have either urls or a static-dist-dir
  if (!urls && !staticDistDir) {
    // Fail and exit
    core.setFailed(`Need either 'urls' in action parameters or a 'static_dist_dir' in lighthouserc file`)
    process.exit(1)
  }

  // Warn if specifying both
  if (urls.length > 0 && staticDistDir) {
    core.warning(
      `Setting both 'url' and 'static_dist_dir' will ignore urls in 'url' since 'static_dist_dir' has higher priority`
    )
  }

  return {
    urls,
    staticDistDir,
    canUpload: getArg('temporaryPublicStorage') ? true : false,
    budgetPath: getArg('budgetPath'),
    numberOfRuns: getIntArg('runs'),
    serverBaseUrl,
    token,
    rcCollect,
    rcAssert,
    configPath
  }