|
| 1 | +# Contributing |
| 2 | + |
| 3 | +Thank you for your interest in contributing to `crates-io-auth-action`! |
| 4 | + |
| 5 | +For non-trivial contributions, please open an issue first to discuss your |
| 6 | +proposed changes before submitting a pull request. |
| 7 | + |
| 8 | +This action is primarily maintained by the Rust Infrastructure Team. |
| 9 | +To chat with us, open a topic in the |
| 10 | +[t-infra Zulip channel](https://rust-lang.zulipchat.com/#narrow/channel/242791-t-infra). |
| 11 | + |
| 12 | +## Running the action |
| 13 | + |
| 14 | +You can't run this action locally as it requires a GitHub environment. |
| 15 | + |
| 16 | +## Install node dependencies |
| 17 | + |
| 18 | +To install node dependencies, run: |
| 19 | + |
| 20 | +```sh |
| 21 | +npm install |
| 22 | +``` |
| 23 | + |
| 24 | +### Packaging |
| 25 | + |
| 26 | +The action code is located in `src/`. |
| 27 | +After editing the code, run the following command to |
| 28 | +compile the TypeScript code and its dependencies into a single file |
| 29 | +in the `dist/` directory: |
| 30 | + |
| 31 | +```sh |
| 32 | +npm run package |
| 33 | +``` |
| 34 | + |
| 35 | +This approach is inspired by the [typescript-action](https://github.com/actions/typescript-action) |
| 36 | +repository and avoids committing the `node_modules` directory to the repository. |
| 37 | + |
| 38 | +To keep these files from displaying in diffs by default or counting toward the repository language, |
| 39 | +we added the `dist/` directory to the [`.gitattributes`](.gitattributes) file with the |
| 40 | +`linguist-generated=true` attribute. |
| 41 | +You can learn more about this in the |
| 42 | +[GitHub docs](https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github). |
| 43 | + |
| 44 | +### Formatting |
| 45 | + |
| 46 | +We use [Prettier](https://prettier.io/) to format TypeScript, Markdown, and YAML files. |
| 47 | +To format all files, run: |
| 48 | + |
| 49 | +```sh |
| 50 | +npx prettier --write . |
| 51 | +``` |
| 52 | + |
| 53 | +### Linting |
| 54 | + |
| 55 | +We use [ESLint](https://eslint.org/) for linting TypeScript files. |
| 56 | + |
| 57 | +To check for linting errors, run: |
| 58 | + |
| 59 | +```sh |
| 60 | +npx eslint |
| 61 | +``` |
| 62 | + |
| 63 | +### Testing |
| 64 | + |
| 65 | +There are two types of tests running in [ci.yml](.github/workflows/ci.yml): |
| 66 | + |
| 67 | +- `action-test`: Tests the action directly by running it against a mock server. |
| 68 | + You can't run this job locally as it requires a GitHub environment. |
| 69 | +- `test`: Tests the JavaScript code by emulating a GitHub environment through |
| 70 | + environment variables and mocking the `@actions/core` library. |
| 71 | + To run these tests locally, run: |
| 72 | + |
| 73 | + ```sh |
| 74 | + npm run test |
| 75 | + ``` |
| 76 | + |
| 77 | +## Crates.io Documentation |
| 78 | + |
| 79 | +To view the Crates.io OpenAPI documentation, |
| 80 | +copy and paste `https://crates.io/api/openapi.json` |
| 81 | +into the [Swagger](https://petstore.swagger.io/) bar at the top of the page. |
| 82 | + |
| 83 | +## GitHub Documentation |
| 84 | + |
| 85 | +Here are some useful links to the GitHub documentation: |
| 86 | + |
| 87 | +- [Creating a JavaScript action](https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-javascript-action) |
| 88 | +- [OpenID Connect](https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/about-security-hardening-with-openid-connect) |
| 89 | + |
| 90 | +## FAQ |
| 91 | + |
| 92 | +### Why TypeScript? |
| 93 | + |
| 94 | +There are 3 types of GitHub Actions: |
| 95 | + |
| 96 | +1. **Docker Actions**: Slower than other types because they require pulling a Docker image. |
| 97 | +2. **Composite Actions**: Don't support [runs.post] for job cleanup after the action runs. |
| 98 | + We need this feature to revoke the token after job completion. |
| 99 | +3. **JavaScript Actions**: |
| 100 | + - Faster than Docker Actions (no Docker image required). |
| 101 | + - Support [runs.post] for job cleanup, so that we can revoke the token. |
| 102 | + - Include GitHub's `@actions/core` library for easy output handling and error management. |
| 103 | + |
| 104 | +We chose a JavaScript Action for these benefits and use TypeScript for type safety. |
| 105 | + |
| 106 | +[runs.post]: https://docs.github.com/en/actions/sharing-automations/creating-actions/metadata-syntax-for-github-actions#runspost |
| 107 | + |
| 108 | +### Why Node 20? |
| 109 | + |
| 110 | +We use Node 20 because it's the latest Node version supported by GitHub Actions. |
| 111 | +The Node version used by this action is specified in the `action.yml` file. |
0 commit comments