Skip to content

Environment

Source: src/GitHub/Environment.ts

A GitHub Actions deployment environment.

Environment manages a repository’s deployment environment (e.g. production, staging) along with its protection rules: required reviewers, wait timers, self-review prevention, and deployment branch policies. Pair it with GitHub.Secret and GitHub.Variable (both accept an environment prop) to scope configuration to the environment.

Environments are available on public repositories on every plan; private repositories require GitHub Pro, Team, or Enterprise, and protection rules on private repositories require Team or Enterprise.

Authentication is resolved via the GitHubCredentials service supplied by GitHub.providers() (env, stored PAT, gh CLI, or OAuth). The token needs repo scope.

Basic Environment

const production = yield* GitHub.Environment("production", {
owner: "my-org",
repository: "my-repo",
name: "production",
});

Environment with Protection Rules

yield* GitHub.Environment("production", {
owner: "my-org",
repository: "my-repo",
name: "production",
waitTimer: 30,
preventSelfReview: true,
reviewers: {
users: ["release-manager"],
teams: ["platform"],
},
});

Restrict to Protected Branches

yield* GitHub.Environment("production", {
owner: "my-org",
repository: "my-repo",
name: "production",
deploymentBranchPolicy: { protectedBranches: true },
});

Restrict to Branch Name Patterns

yield* GitHub.Environment("production", {
owner: "my-org",
repository: "my-repo",
name: "production",
deploymentBranchPolicy: {
customBranchPolicies: ["main", "release/*"],
},
});
const env = yield* GitHub.Environment("production", {
owner: "my-org",
repository: "my-repo",
name: "production",
});
yield* GitHub.Secret("deploy-key", {
owner: "my-org",
repository: "my-repo",
environment: env,
name: "DEPLOY_KEY",
value: Redacted.make("my-secret-value"),
});
yield* GitHub.Variable("region", {
owner: "my-org",
repository: "my-repo",
environment: env,
name: "AWS_REGION",
value: "us-east-1",
});