# S5 deployment kit

> **Guided practice with fictional data.** First prepare an authorised practice repo and Apps Script copy. Keep its existing deployment with restricted access. Do not start with an app in service.

## 1. What you download

[Download the S5 ZIP kit](../../../sessio_5/exemple/kit-s5.en.zip). Extract it into an empty folder and read the files before copying them into the repo.

| ZIP file | Destination in the practice repo |
|---|---|
| `.github/workflows/deploy.yml` | Same path; compare it if a workflow already exists |
| `course-tools/deploy.mjs` | Same path |
| `course-tools/package.json` and `package-lock.json` | Both inside `course-tools/` |
| `gitignore-additions.txt` | Add entries to your `.gitignore` without replacing it |
| `README.md` | Package instructions in English |

The kit **contains no app, manifest or credentials**. It needs your existing code. It pins `clasp` to **3.4.1**, Node to **24** and both actions to specific commits. If you change versions, review official release notes and repeat tests. It does not replace app logic review.

It also pins **Zod 4.6.6** with an explicit override to address [GHSA-mrhx-c7xc-m3w5](https://github.com/advisories/GHSA-mrhx-c7xc-m3w5). Installation, CLI startup and dependency audit have been checked. The kit uses only the CLI commands described here; it does not activate clasp’s MCP server. This adjustment does not verify other uses or replace Google tests.

## 2. Check that the project fits

This example accepts only **`Codi.gs`, `Index.html` and `appsscript.json` at the repo root**. Export all code from the practice copy. In Apps Script settings, show the manifest and preserve it unchanged. It must use V8.

If there are more files, other names, libraries or a changed manifest, **stop and adapt the plan** with help. Do not delete files to pass the check. `clasp push` may replace the entire remote project; an upload is not a transaction that rolls itself back on failure.

In the repo’s `Codi.gs`, keep a single constant with the S1 marker:

```javascript
const ID_DEL_FULL = 'ENGANXA_AQUI_ID_DEL_FULL';
```

The kit replaces the marker in a temporary copy, never in the repo. Existing Apps Script code must point to the correct practice spreadsheet. If the repo contains a real ID, review its exposure and change it consciously; do not copy it into chat.

## 3. Identify the three destinations

| GitHub Actions variable | What it identifies | Where to find it |
|---|---|---|
| `SPREADSHEET_ID` | Practice spreadsheet | Sheets document URL |
| `SCRIPT_ID` | Apps Script project | Project Settings |
| `DEPLOYMENT_ID` | Existing deployment serving the same `/exec` | Deploy → Manage deployments |
| `AUTO_DEPLOY` | Whether a push to `main` can publish | Leave empty initially |

These are not interchangeable. The kit checks that the deployment belongs to the project, has a version, and remote code points to the specified spreadsheet. IDs are not passwords, but need not be published in the repo or examples.

## 4. Authorise outside chat

First review code, workflow, authorised account, organisational policies and Actions quotas. Do not switch accounts to bypass a restriction. Real practice needs permissions over the project, spreadsheet and repo settings.

In a trusted environment with compatible Node, install the pinned version:

```sh
npm ci --prefix course-tools --ignore-scripts --no-audit --no-fund
node course-tools/node_modules/@google/clasp/build/src/index.js --version
node course-tools/node_modules/@google/clasp/build/src/index.js login
```

The version must be `3.4.1`. Login opens Google consent: check the account and permissions before accepting. If the remote environment cannot receive the redirect, consult the same version’s `login --no-localhost` option and follow its instructions without publishing the return URL. OAuth may need a Google Cloud client or administrator involvement.

Check Apps Script API access in [user settings](https://script.google.com/home/usersettings). A denial may also come from permissions, consent, policies or expired credentials; do not always blame the API.

Login saves a credential in **`.clasprc.json` in your home folder**. This is not the project’s `.clasp.json`. Do not show it in screenshots, logs or prompts. If you have authorised this exercise, copy its contents **directly** into the Actions secret `CLASPRC_JSON`, under Settings → Secrets and variables → Actions. Configure table variables separately. Do not add the credential to the repo. Afterwards review whether to retain or revoke authorisation.

The kit creates the credential temporarily only on a GitHub-hosted runner, without overwriting existing files, and removes it afterwards. Do not run the deployer directly on your computer. A workflow with secret access can use it: review changes to these files carefully and do not run unreviewed branch code with credentials.

## 5. First manual run

1. Add the kit and complete code on a branch. Review diff, manifest and dependencies. Check logic with S1/S2 tests in the practice copy.
2. Open the PR, record the reviewed commit and merge only ready changes. **`AUTO_DEPLOY` stays empty**: push must not publish.
3. In Actions, open “Deploy the Apps Script practice” → Run workflow → `main`. Check the commit being run. If unavailable, confirm the workflow exists on the default branch and Actions is allowed.
4. Read the result and record the **previous version** shown. The deployer checks files and syntax, downloads remote code, compares inventory, spreadsheet and manifest, uploads all three files and downloads them again for comparison.
5. Only then does it create a version and update the **same Deployment ID**. It uses no `--force` and creates no new URL.
6. Open the same `/exec` with the authorised account: test a valid record, rejected value, writes to the correct spreadsheet and access with an account that should not enter. Also check visible form errors. Record results and pending work in the [test worksheet](fitxa-proves-s4-s5.md).

**A green job does not test business logic, access or every app path.** Material tests simulate `clasp`; OAuth consent and Google tests must be verified in your environment. Without access, leave them pending; do not mark publishing checked.

## 6. Automate only when ready

You can keep manual runs. If you enable `AUTO_DEPLOY=true`, future pushes to `main` can publish, including those without a PR if no rule blocks them. This includes workflow changes.

Apply available account protections. Private repo branch rules require a compatible plan; review administrator exceptions. Do not make the repo public or buy a plan just for this exercise. Without effective protection, keep manual publishing and review the commit before running. Working alone, do not require an impossible external approval.

## 7. On failure or recovery

- **Before push:** the kit stops if destination, inventory or manifest do not fit. Fix the plan; do not remove checks to continue.
- **After push:** editor code and `/dev` may have changed even if `/exec` remains on the previous version. Inspect state before retrying.
- **After publishing:** clear `AUTO_DEPLOY` and check active or queued runs. In Manage deployments, select the previous version of the same deployment and check `/exec`. Also review the repo through a fix or revert PR before resuming.
- **Re-run jobs** uses the original commit, not a later fix. Always identify the SHA and avoid blind retries.
- Recovering code **does not recover spreadsheet data**. Data needs a separate backup or procedure.

## Sources and maintenance

- [clasp 3.4.1: commands, authentication and push](https://github.com/google/clasp/blob/v3.4.1/README.md).
- [Web apps and test URLs](https://developers.google.com/apps-script/guides/web).
- [Versions and deployments](https://developers.google.com/apps-script/concepts/deployments).
- [Deployment management API](https://developers.google.com/apps-script/api/how-tos/manage-deployments).
- [Branch protection](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches) and [rulesets](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/about-rulesets).

Reviewed on 2026-10-26. Pinned versions make the example reproducible; they do not guarantee security or replace maintenance.
