# atmos pro commit

Use this command to commit staged changes via the [Atmos Pro](https://atmos-pro.com/docs) GitHub App.
Unlike commits made with `GITHUB_TOKEN`, commits created through Atmos Pro trigger subsequent CI runs.

## Usage

```shell
atmos pro commit --message <message> [--comment <comment>] [--add <pattern>] [--all]
```

## Description

When running in GitHub Actions, commits made with `GITHUB_TOKEN` do not trigger subsequent workflow runs.
This is a deliberate GitHub limitation to prevent infinite loops, but it also prevents autofix workflows
(like `terraform fmt`) from triggering validation on the reformatted code.

`atmos pro commit` solves this by sending your changes to Atmos Pro, which creates the commit server-side
using its GitHub App installation. Because the commit comes from the app (not `GITHUB_TOKEN`), GitHub
triggers CI normally.

The workflow never receives a write token. Atmos Pro controls exactly what gets committed.

:::info Loop Prevention
The command automatically detects when it's running in a workflow triggered by `atmos-pro[bot]` and
exits early with a success message. This prevents infinite commit loops without requiring any workflow
configuration. You can optionally add `if: github.actor != 'atmos-pro[bot]'` to skip the entire job
for efficiency.
:::

## Examples

```shell
# Commit whatever is already staged
atmos pro commit -m "terraform fmt"

# Stage all changes then commit
atmos pro commit -m "terraform fmt" --all

# Stage only .tf files then commit
atmos pro commit -m "terraform fmt" --add "*.tf"

# Include a PR comment alongside the commit
atmos pro commit -m "terraform fmt" --comment "Auto-formatted Terraform files"
```

### Example GitHub Actions Workflow

```yaml
name: autocommit
on: pull_request

permissions:
  contents: read
  id-token: write

jobs:
  format:
    if: github.actor != 'atmos-pro[bot]'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - run: terraform fmt -recursive
      - run: atmos pro commit -m "[autocommit] terraform fmt" --all
```

## Flags

- **`--message` (alias `-m`) (required)** — Commit message. Maximum 500 characters.
- **`--comment` (optional)** — PR comment to post alongside the commit. Maximum 2000 characters.
- **`--add` (optional)** — File pattern to stage before committing (e.g. `"*.tf"`). Runs `git add <pattern>`. Mutually exclusive with `--all`.
- **`--all` (alias `-A`) (optional)** — Stage all changes before committing (runs `git add -A`). Mutually exclusive with `--add`.

## Environment Variables

- **`ATMOS_PRO_BASE_URL`** — Atmos Pro API URL (e.g. `https://app.atmos.pro`). Can also be set in `atmos.yaml`.
- **`ATMOS_PRO_WORKSPACE_ID`** — Workspace ID for OIDC authentication.
- **`GITHUB_HEAD_REF`** — PR branch name. Set automatically by GitHub Actions on `pull_request` events. Required.
- **`ACTIONS_ID_TOKEN_REQUEST_URL`** — GitHub Actions OIDC token endpoint. Set automatically when `id-token: write` permission is granted.
- **`ACTIONS_ID_TOKEN_REQUEST_TOKEN`** — GitHub Actions OIDC request bearer token. Set automatically when `id-token: write` permission is granted.
