mirror of
https://github.com/FranzDiebold/github-env-vars-action.git
synced 2024-12-29 02:14:51 -05:00
Merge branch 'primary' into demo/demo-branch-for-pull-request
This commit is contained in:
commit
104470dfb0
6 changed files with 12897 additions and 241 deletions
6
.github/workflows/demo.yml
vendored
6
.github/workflows/demo.yml
vendored
|
@ -28,6 +28,8 @@ jobs:
|
|||
echo "CI_BASE_REF=$CI_BASE_REF"
|
||||
echo "CI_SHA_SHORT=$CI_SHA_SHORT"
|
||||
echo "CI_SHA=$CI_SHA"
|
||||
echo "CI_PR_TITLE=$CI_PR_TITLE"
|
||||
echo "CI_PR_DESCRIPTION=$CI_PR_DESCRIPTION"
|
||||
echo "CI_ACTOR=$CI_ACTOR"
|
||||
echo "CI_EVENT_NAME=$CI_EVENT_NAME"
|
||||
echo "CI_RUN_ID=$CI_RUN_ID"
|
||||
|
@ -73,6 +75,8 @@ jobs:
|
|||
echo "CI_BASE_REF=$Env:CI_BASE_REF"
|
||||
echo "CI_SHA_SHORT=$Env:CI_SHA_SHORT"
|
||||
echo "CI_SHA=$Env:CI_SHA"
|
||||
echo "CI_PR_TITLE=$Env:CI_PR_TITLE"
|
||||
echo "CI_PR_DESCRIPTION=$Env:CI_PR_DESCRIPTION"
|
||||
echo "CI_ACTOR=$Env:CI_ACTOR"
|
||||
echo "CI_EVENT_NAME=$Env:CI_EVENT_NAME"
|
||||
echo "CI_RUN_ID=$Env:CI_RUN_ID"
|
||||
|
@ -118,6 +122,8 @@ jobs:
|
|||
echo "CI_BASE_REF=$CI_BASE_REF"
|
||||
echo "CI_SHA_SHORT=$CI_SHA_SHORT"
|
||||
echo "CI_SHA=$CI_SHA"
|
||||
echo "CI_PR_TITLE=$CI_PR_TITLE"
|
||||
echo "CI_PR_DESCRIPTION=$CI_PR_DESCRIPTION"
|
||||
echo "CI_ACTOR=$CI_ACTOR"
|
||||
echo "CI_EVENT_NAME=$CI_EVENT_NAME"
|
||||
echo "CI_RUN_ID=$CI_RUN_ID"
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
[![GitHub Action: View on Marketplace](https://img.shields.io/badge/GitHub%20Action-View_on_Marketplace-28a745?logo=github)](https://github.com/marketplace/actions/github-environment-variables-action)
|
||||
[![Demo: available](https://img.shields.io/badge/Demo-available-orange)](.github/workflows/demo.yml)
|
||||
[![Version: v2.1.0](https://img.shields.io/badge/Version-v2.1.0-brightgreen)](https://github.com/FranzDiebold/github-env-vars-action/releases/tag/v2.1.0)
|
||||
[![Version: v2.3.0](https://img.shields.io/badge/Version-v2.3.0-brightgreen)](https://github.com/FranzDiebold/github-env-vars-action/releases/tag/v2.3.0)
|
||||
[![Lint and Test](https://github.com/FranzDiebold/github-env-vars-action/workflows/Lint%20and%20Test/badge.svg)](https://github.com/FranzDiebold/github-env-vars-action/actions?query=workflow%3A%22Lint+and+Test%22)
|
||||
[![license: MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](./LICENSE)
|
||||
|
||||
|
@ -32,6 +32,8 @@ A [GitHub Action](https://github.com/features/actions) to expose useful environm
|
|||
| `CI_BASE_REF` | Only set for forked repositories / pull request. The branch of the base repository / the base branch name. Copy of `GITHUB_BASE_REF` - for reasons of completeness. | `main` |
|
||||
| `CI_SHA_SHORT` | The shortened commit SHA (8 characters) that triggered the workflow. | `ffac537e` |
|
||||
| `CI_SHA` | The commit SHA that triggered the workflow. Copy of `GITHUB_SHA` - for reasons of completeness. | `ffac537e6cbbf934b08745a378932722df287a53` |
|
||||
| `CI_PR_TITLE` | The title of the pull request. Only set for pull requests. | `Add feature xyz.` |
|
||||
| `CI_PR_DESCRIPTION` | The description of the pull request. Only set for pull requests. | `The feature xyz is the [...]` |
|
||||
| `CI_ACTOR` | The name of the person or app that initiated the workflow. Copy of `GITHUB_ACTOR` - for reasons of completeness. | `octocat` |
|
||||
| `CI_EVENT_NAME` | The name of the webhook event that triggered the workflow. Copy of `GITHUB_EVENT_NAME` - for reasons of completeness. | `push` or `pull_request` |
|
||||
| `CI_RUN_ID` | A unique number for each run within a repository. This number does not change if you re-run the workflow run. Copy of `GITHUB_RUN_ID` - for reasons of completeness. | `397746731` |
|
||||
|
|
5784
dist/index.js
vendored
5784
dist/index.js
vendored
File diff suppressed because one or more lines are too long
104
index.js
104
index.js
|
@ -1,6 +1,7 @@
|
|||
// Franz Diebold
|
||||
|
||||
const core = require('@actions/core');
|
||||
const github = require('@actions/github');
|
||||
|
||||
/**
|
||||
* Slugify a given string.
|
||||
|
@ -56,64 +57,64 @@ function getShaShort(fullSha) {
|
|||
|
||||
try {
|
||||
// i.e. FranzDiebold/github-env-vars-action
|
||||
repository = process.env.GITHUB_REPOSITORY;
|
||||
const repository = process.env.GITHUB_REPOSITORY;
|
||||
|
||||
if (repository) {
|
||||
core.exportVariable('CI_REPOSITORY_SLUG', slugify(repository));
|
||||
core.info(`Set CI_REPOSITORY_SLUG=` +
|
||||
`${process.env.CI_REPOSITORY_SLUG}`);
|
||||
`${process.env.CI_REPOSITORY_SLUG}`);
|
||||
} else {
|
||||
core.warning('Environment variable "GITHUB_REPOSITORY" not set. ' +
|
||||
'Cannot set "CI_REPOSITORY_SLUG".');
|
||||
core.info('Environment variable "GITHUB_REPOSITORY" not set. ' +
|
||||
'Cannot set "CI_REPOSITORY_SLUG".');
|
||||
}
|
||||
|
||||
repositoryOwner = getRepositoryOwner(repository);
|
||||
const repositoryOwner = getRepositoryOwner(repository);
|
||||
if (repositoryOwner) {
|
||||
core.exportVariable('CI_REPOSITORY_OWNER', repositoryOwner);
|
||||
core.info(`Set CI_REPOSITORY_OWNER=` +
|
||||
`${process.env.CI_REPOSITORY_OWNER}`);
|
||||
`${process.env.CI_REPOSITORY_OWNER}`);
|
||||
|
||||
core.exportVariable('CI_REPOSITORY_OWNER_SLUG',
|
||||
slugify(repositoryOwner));
|
||||
core.info(`Set CI_REPOSITORY_OWNER_SLUG=` +
|
||||
`${process.env.CI_REPOSITORY_OWNER_SLUG}`);
|
||||
`${process.env.CI_REPOSITORY_OWNER_SLUG}`);
|
||||
} else {
|
||||
core.warning('Environment variable "GITHUB_REPOSITORY" not set. ' +
|
||||
'Cannot set "CI_REPOSITORY_OWNER" and ' +
|
||||
'"CI_REPOSITORY_OWNER_SLUG".');
|
||||
core.info('Environment variable "GITHUB_REPOSITORY" not set. ' +
|
||||
'Cannot set "CI_REPOSITORY_OWNER" and ' +
|
||||
'"CI_REPOSITORY_OWNER_SLUG".');
|
||||
}
|
||||
|
||||
repositoryName = getRepositoryName(repository);
|
||||
const repositoryName = getRepositoryName(repository);
|
||||
if (repositoryName) {
|
||||
core.exportVariable('CI_REPOSITORY_NAME', repositoryName);
|
||||
core.info(`Set CI_REPOSITORY_NAME=` +
|
||||
`${process.env.CI_REPOSITORY_NAME}`);
|
||||
`${process.env.CI_REPOSITORY_NAME}`);
|
||||
|
||||
core.exportVariable('CI_REPOSITORY_NAME_SLUG',
|
||||
slugify(repositoryName));
|
||||
core.info(`Set CI_REPOSITORY_NAME_SLUG=` +
|
||||
`${process.env.CI_REPOSITORY_NAME_SLUG}`);
|
||||
`${process.env.CI_REPOSITORY_NAME_SLUG}`);
|
||||
} else {
|
||||
core.warning('Environment variable "GITHUB_REPOSITORY" not set. ' +
|
||||
'Cannot set "CI_REPOSITORY_NAME" and ' +
|
||||
'"CI_REPOSITORY_NAME_SLUG".');
|
||||
core.info('Environment variable "GITHUB_REPOSITORY" not set. ' +
|
||||
'Cannot set "CI_REPOSITORY_NAME" and ' +
|
||||
'"CI_REPOSITORY_NAME_SLUG".');
|
||||
}
|
||||
|
||||
core.exportVariable('CI_REPOSITORY', repository);
|
||||
core.info(`Set CI_REPOSITORY=${process.env.CI_REPOSITORY}`);
|
||||
|
||||
// i.e. refs/heads/feat/feature-branch-1
|
||||
ref = process.env.GITHUB_REF;
|
||||
const ref = process.env.GITHUB_REF;
|
||||
|
||||
if (ref) {
|
||||
core.exportVariable('CI_REF_SLUG', slugify(ref));
|
||||
core.info(`Set CI_REF_SLUG=${process.env.CI_REF_SLUG}`);
|
||||
} else {
|
||||
core.warning('Environment variable "GITHUB_REF" not set. ' +
|
||||
'Cannot set "CI_REF_SLUG".');
|
||||
core.info('Environment variable "GITHUB_REF" not set. ' +
|
||||
'Cannot set "CI_REF_SLUG".');
|
||||
}
|
||||
|
||||
refName = getRefName(ref);
|
||||
const refName = getRefName(ref);
|
||||
if (refName) {
|
||||
core.exportVariable('CI_REF_NAME', refName);
|
||||
core.info(`Set CI_REF_NAME=${process.env.CI_REF_NAME}`);
|
||||
|
@ -121,88 +122,103 @@ try {
|
|||
core.exportVariable('CI_REF_NAME_SLUG', slugify(refName));
|
||||
core.info(`Set CI_REF_NAME_SLUG=${process.env.CI_REF_NAME_SLUG}`);
|
||||
} else {
|
||||
core.warning('Environment variable "GITHUB_REF" not set. ' +
|
||||
'Cannot set "CI_REF_NAME" and ' +
|
||||
'"CI_REF_NAME_SLUG".');
|
||||
core.info('Environment variable "GITHUB_REF" not set. ' +
|
||||
'Cannot set "CI_REF_NAME" and ' +
|
||||
'"CI_REF_NAME_SLUG".');
|
||||
}
|
||||
|
||||
core.exportVariable('CI_REF', ref);
|
||||
core.info(`Set CI_REF=${process.env.CI_REF}`);
|
||||
|
||||
headRef = process.env.GITHUB_HEAD_REF;
|
||||
const headRef = process.env.GITHUB_HEAD_REF;
|
||||
|
||||
branchName = headRef || refName;
|
||||
const branchName = headRef || refName;
|
||||
if (branchName) {
|
||||
core.exportVariable('CI_ACTION_REF_NAME', branchName);
|
||||
core.info(`Set CI_ACTION_REF_NAME=${process.env.CI_ACTION_REF_NAME}`);
|
||||
|
||||
core.exportVariable('CI_ACTION_REF_NAME_SLUG', slugify(branchName));
|
||||
core.info('Set CI_ACTION_REF_NAME_SLUG=' +
|
||||
`${process.env.CI_ACTION_REF_NAME_SLUG}`);
|
||||
`${process.env.CI_ACTION_REF_NAME_SLUG}`);
|
||||
} else {
|
||||
core.warning('Environment variables "GITHUB_REF" and ' +
|
||||
'"GITHUB_HEAD_REF" not set. ' +
|
||||
'Cannot set "CI_ACTION_REF_NAME" and ' +
|
||||
'"CI_ACTION_REF_NAME_SLUG".');
|
||||
core.info('Environment variables "GITHUB_REF" and ' +
|
||||
'"GITHUB_HEAD_REF" not set. ' +
|
||||
'Cannot set "CI_ACTION_REF_NAME" and ' +
|
||||
'"CI_ACTION_REF_NAME_SLUG".');
|
||||
}
|
||||
|
||||
if (headRef) {
|
||||
core.exportVariable('CI_HEAD_REF_SLUG', slugify(headRef));
|
||||
core.info(`Set CI_HEAD_REF_SLUG=${process.env.CI_HEAD_REF_SLUG}`);
|
||||
} else {
|
||||
core.warning('Environment variable "GITHUB_HEAD_REF" not set. ' +
|
||||
'Cannot set "CI_HEAD_REF_SLUG".');
|
||||
core.info('Environment variable "GITHUB_HEAD_REF" not set. ' +
|
||||
'Cannot set "CI_HEAD_REF_SLUG".');
|
||||
}
|
||||
|
||||
core.exportVariable('CI_HEAD_REF', headRef);
|
||||
core.info(`Set CI_HEAD_REF=${process.env.CI_HEAD_REF}`);
|
||||
|
||||
baseRef = process.env.GITHUB_BASE_REF;
|
||||
const baseRef = process.env.GITHUB_BASE_REF;
|
||||
if (baseRef) {
|
||||
core.exportVariable('CI_BASE_REF_SLUG', slugify(baseRef));
|
||||
core.info(`Set CI_BASE_REF_SLUG=${process.env.CI_BASE_REF_SLUG}`);
|
||||
} else {
|
||||
core.warning('Environment variable "GITHUB_BASE_REF" not set. ' +
|
||||
'Cannot set "CI_BASE_REF_SLUG".');
|
||||
core.info('Environment variable "GITHUB_BASE_REF" not set. ' +
|
||||
'Cannot set "CI_BASE_REF_SLUG".');
|
||||
}
|
||||
|
||||
core.exportVariable('CI_BASE_REF', baseRef);
|
||||
core.info(`Set CI_BASE_REF=${process.env.CI_BASE_REF}`);
|
||||
|
||||
// i.e. ffac537e6cbbf934b08745a378932722df287a53
|
||||
sha = process.env.GITHUB_SHA;
|
||||
const sha = process.env.GITHUB_SHA;
|
||||
if (sha) {
|
||||
core.exportVariable('CI_SHA_SHORT', getShaShort(sha));
|
||||
core.info(`Set CI_SHA_SHORT=${process.env.CI_SHA_SHORT}`);
|
||||
} else {
|
||||
core.warning('Environment variable "GITHUB_SHA" not set. ' +
|
||||
'Cannot set "CI_SHA_SHORT".');
|
||||
core.info('Environment variable "GITHUB_SHA" not set. ' +
|
||||
'Cannot set "CI_SHA_SHORT".');
|
||||
}
|
||||
|
||||
core.exportVariable('CI_SHA', sha);
|
||||
core.info(`Set CI_SHA=${process.env.CI_SHA}`);
|
||||
|
||||
actor = process.env.GITHUB_ACTOR;
|
||||
const pullRequest = github.context.payload &&
|
||||
github.context.payload.pull_request;
|
||||
if (pullRequest) {
|
||||
const prTitle = pullRequest.title;
|
||||
core.exportVariable('CI_PR_TITLE', prTitle);
|
||||
core.info(`Set CI_PR_TITLE=${process.env.CI_PR_TITLE}`);
|
||||
|
||||
const prDescription = pullRequest.body;
|
||||
core.exportVariable('CI_PR_DESCRIPTION', prDescription);
|
||||
core.info(`Set CI_PR_DESCRIPTION=${process.env.CI_PR_DESCRIPTION}`);
|
||||
} else {
|
||||
core.info('No pull request. ' +
|
||||
'Cannot set "CI_PR_TITLE" and "CI_PR_DESCRIPTION".');
|
||||
}
|
||||
|
||||
const actor = process.env.GITHUB_ACTOR;
|
||||
core.exportVariable('CI_ACTOR', actor);
|
||||
core.info(`Set CI_ACTOR=${process.env.CI_ACTOR}`);
|
||||
|
||||
eventName = process.env.GITHUB_EVENT_NAME;
|
||||
const eventName = process.env.GITHUB_EVENT_NAME;
|
||||
core.exportVariable('CI_EVENT_NAME', eventName);
|
||||
core.info(`Set CI_EVENT_NAME=${process.env.CI_EVENT_NAME}`);
|
||||
|
||||
runId = process.env.GITHUB_RUN_ID;
|
||||
const runId = process.env.GITHUB_RUN_ID;
|
||||
core.exportVariable('CI_RUN_ID', runId);
|
||||
core.info(`Set CI_RUN_ID=${process.env.CI_RUN_ID}`);
|
||||
|
||||
runNumber = process.env.GITHUB_RUN_NUMBER;
|
||||
const runNumber = process.env.GITHUB_RUN_NUMBER;
|
||||
core.exportVariable('CI_RUN_NUMBER', runNumber);
|
||||
core.info(`Set CI_RUN_NUMBER=${process.env.CI_RUN_NUMBER}`);
|
||||
|
||||
workflow = process.env.GITHUB_WORKFLOW;
|
||||
const workflow = process.env.GITHUB_WORKFLOW;
|
||||
core.exportVariable('CI_WORKFLOW', workflow);
|
||||
core.info(`Set CI_WORKFLOW=${process.env.CI_WORKFLOW}`);
|
||||
|
||||
action = process.env.GITHUB_ACTION;
|
||||
const action = process.env.GITHUB_ACTION;
|
||||
core.exportVariable('CI_ACTION', action);
|
||||
core.info(`Set CI_ACTION=${process.env.CI_ACTION}`);
|
||||
} catch (error) {
|
||||
|
|
7231
package-lock.json
generated
7231
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "github-env-vars-action",
|
||||
"version": "2.1.0",
|
||||
"version": "2.3.0",
|
||||
"description": "A GitHub Action to expose useful environment variables.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
@ -23,11 +23,12 @@
|
|||
},
|
||||
"homepage": "https://github.com/FranzDiebold/github-env-vars-action#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6"
|
||||
"@actions/core": "^1.2.7",
|
||||
"@actions/github": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vercel/ncc": "^0.25.1",
|
||||
"eslint": "^7.14.0",
|
||||
"@vercel/ncc": "^0.28.5",
|
||||
"eslint": "^7.25.0",
|
||||
"eslint-config-google": "^0.14.0",
|
||||
"jest": "^26.6.3"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue