Skip to content

Commit 18fddaa

Browse files
committed
import project
1 parent 5dc892d commit 18fddaa

34 files changed

+60721
-1
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/ linguist-generated=true

.github/workflows/ci.yml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- "main"
8+
pull_request:
9+
10+
permissions: {}
11+
12+
jobs:
13+
test:
14+
name: Test
15+
runs-on: ubuntu-24.04
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
with:
20+
persist-credentials: false
21+
22+
- name: Install node dependencies
23+
run: npm ci
24+
25+
- name: Test
26+
run: |
27+
npm run test
28+
29+
lint:
30+
name: Lint
31+
runs-on: ubuntu-24.04
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v4
35+
with:
36+
persist-credentials: false
37+
38+
- name: Install node dependencies
39+
run: npm ci
40+
41+
- name: Lint
42+
run: |
43+
npm run lint
44+
45+
format:
46+
name: Format
47+
runs-on: ubuntu-24.04
48+
steps:
49+
- name: Checkout repository
50+
uses: actions/checkout@v4
51+
with:
52+
persist-credentials: false
53+
54+
- name: Install Prettier
55+
run: npm ci
56+
57+
- name: Format
58+
run: npx prettier --check .
59+
60+
zizmor:
61+
name: Zizmor
62+
runs-on: ubuntu-24.04
63+
steps:
64+
- name: Checkout repository
65+
uses: actions/checkout@v4
66+
with:
67+
persist-credentials: false
68+
69+
- name: Run zizmor
70+
uses: zizmorcore/zizmor-action@f52a838cfabf134edcbaa7c8b3677dde20045018 # v0.1.1
71+
with:
72+
persona: pedantic
73+
# Don't use GitHub advanced security.
74+
# Instead, fail if there's a security issue.
75+
advanced-security: false
76+
77+
package:
78+
name: Package
79+
runs-on: ubuntu-24.04
80+
steps:
81+
- name: Checkout repository
82+
uses: actions/checkout@v4
83+
with:
84+
persist-credentials: false
85+
86+
- name: Install node dependencies
87+
run: npm ci
88+
89+
- name: Check is packaged
90+
run: |
91+
# Compile to single js files.
92+
npm run package
93+
94+
# Assert that the git diff is empty.
95+
git diff --exit-code || (echo "Git diff is not empty. Please run 'npm run package' and commit the changes." && exit 1)
96+
97+
# This job tests the action directly by running it against a mock server.
98+
action-test:
99+
name: Action Test
100+
runs-on: ubuntu-24.04
101+
102+
# Required for OpenID Connect token retrieval.
103+
permissions:
104+
id-token: write
105+
106+
steps:
107+
- name: Checkout repository
108+
uses: actions/checkout@v4
109+
with:
110+
persist-credentials: false
111+
112+
- name: Start mock crates.io server
113+
run: |
114+
# Build the mock server in advance so that the binary is already built
115+
# when we start checking the health endpoint.
116+
manifest_path="--manifest-path=mock/Cargo.toml"
117+
cargo build $manifest_path
118+
# Run the mock server in the background.
119+
cargo run $manifest_path &
120+
121+
# Wait for server to be ready.
122+
retry_count=0
123+
max_retries=3
124+
until curl -s http://localhost:3000/health > /dev/null 2>&1; do
125+
echo "Waiting for mock server to start... (attempt $((retry_count + 1))/$max_retries)"
126+
sleep 2
127+
retry_count=$((retry_count + 1))
128+
if [ $retry_count -ge $max_retries ]; then
129+
echo "Mock server failed to start after $max_retries attempts"
130+
exit 1
131+
fi
132+
done
133+
echo "Mock server is ready"
134+
135+
- name: Run trusted publishing action
136+
id: trusted-publishing
137+
uses: ./ # Uses the action in the root directory.
138+
with:
139+
url: "http://localhost:3000" # Mock server url.
140+
141+
- name: Assert action output
142+
env:
143+
TOKEN: ${{ steps.trusted-publishing.outputs.token }}
144+
run: |
145+
if [ "$TOKEN" != "mock-token" ]; then
146+
echo "Expected token to be 'mock-token', but got '$TOKEN'"
147+
exit 1
148+
fi
149+
echo "Token assertion passed. Token value: $TOKEN"

.github/workflows/links.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Check if links present in the repository are valid.
2+
3+
name: Links
4+
5+
on:
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
permissions: {}
16+
17+
jobs:
18+
check-links:
19+
name: Check links
20+
runs-on: ubuntu-24.04
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
with:
25+
persist-credentials: false
26+
27+
- name: Link Checker
28+
uses: lycheeverse/lychee-action@82202e5e9c2f4ef1a55a3d02563e1cb6041e5332 # v2.4.1
29+
env:
30+
# Set the GitHub token to avoid rate limits when checking GitHub links.
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
with:
33+
fail: true
34+
# Accept the HTTP status code 429 (Too Many Requests) to avoid failing the workflow
35+
# when the rate limit is exceeded.
36+
args: |
37+
--no-progress
38+
--include-fragments
39+
--accept '100..=103, 200..=299, 429'
40+
.

.github/workflows/mock.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Mock CI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- "main"
8+
paths:
9+
- "mock"
10+
pull_request:
11+
paths:
12+
- "mock"
13+
14+
permissions: {}
15+
16+
jobs:
17+
rustfmt:
18+
name: Rustfmt
19+
runs-on: ubuntu-24.04
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
with:
24+
persist-credentials: false
25+
26+
- name: Check formatting
27+
run: cargo fmt --all --check
28+
29+
clippy:
30+
name: Clippy
31+
runs-on: ubuntu-24.04
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v4
35+
with:
36+
persist-credentials: false
37+
38+
- name: Clippy check
39+
run: cargo clippy --all-targets --all-features --workspace -- -D warnings

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
.vscode
3+
.idea
4+
mock/target
5+
node_modules/
6+
*.js.map

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore artifacts:
2+
dist

.prettierrc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"tabWidth": 4,
3+
"useTabs": false,
4+
"overrides": [
5+
{
6+
"files": ["*.yml", "*.yaml", "*.md"],
7+
"options": {
8+
"tabWidth": 2
9+
}
10+
}
11+
]
12+
}

CODE_OF_CONDUCT.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The Rust Code of Conduct
2+
3+
The Code of Conduct for this repository [can be found online](https://www.rust-lang.org/conduct.html).

CONTRIBUTING.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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

Comments
 (0)