Skip to content

Commit 949e431

Browse files
committed
import project
1 parent 5dc892d commit 949e431

31 files changed

+60376
-1
lines changed

.github/workflows/ci.yml

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

.github/workflows/links.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
linkChecker:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
with:
24+
persist-credentials: false
25+
26+
- name: Link Checker
27+
uses: lycheeverse/lychee-action@82202e5e9c2f4ef1a55a3d02563e1cb6041e5332 # v2.4.1
28+
env:
29+
# Set the GitHub token to avoid rate limits when checking GitHub links.
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
with:
32+
fail: true
33+
# Accept the HTTP status code 429 (Too Many Requests) to avoid failing the workflow
34+
# when the rate limit is exceeded.
35+
args: |
36+
--no-progress
37+
--include-fragments
38+
--accept '100..=103, 200..=299, 429'
39+
.

.github/workflows/mock.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
runs-on: ubuntu-24.04
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
with:
23+
persist-credentials: false
24+
25+
- name: Check formatting
26+
run: cargo fmt --all --check
27+
28+
clippy:
29+
name: Clippy
30+
runs-on: ubuntu-24.04
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
with:
35+
persist-credentials: false
36+
37+
- name: Clippy check
38+
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+
}

CONTRIBUTING.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Contributing
2+
3+
## Local development
4+
5+
You can't run or test this action locally because it requires a GitHub environment to run.
6+
7+
## Install node dependencies
8+
9+
To install the node dependencies, run:
10+
11+
```bash
12+
npm install
13+
```
14+
15+
### Packaging
16+
17+
The code of the action is in `src/`.
18+
After you edit the code, run the following command to
19+
compile the typescript code and its dependencies into a single typescript
20+
file in the `dist/` directory:
21+
22+
```bash
23+
npm run package
24+
```
25+
26+
This approach is inspired by the [typescript-action](https://github.com/actions/typescript-action)
27+
repository and it's used to avoid committing the `node_modules` directory to the repository.
28+
29+
### Format
30+
31+
We use [Prettier](https://prettier.io/) for formatting typescript, markdown, and YAML files.
32+
To format all files, run:
33+
34+
```bash
35+
npx prettier --write .
36+
```
37+
38+
### Linting
39+
40+
We use [ESLint](https://eslint.org/) for formatting and linting typescript files.
41+
42+
To check for linting errors, run:
43+
44+
```bash
45+
npx eslint
46+
```
47+
48+
## Crates.io docs
49+
50+
To check the Crates.io OpenAPI documentation,
51+
copy paste `https://crates.io/api/openapi.json`
52+
in the [swagger](https://petstore.swagger.io/) bar at the top of the page.
53+
54+
## GitHub docs
55+
56+
Here are some useful links to the GitHub documentation:
57+
58+
- [Creating a javascript action](https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-javascript-action)
59+
- [OpenID Connect](https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
60+
61+
## FAQ
62+
63+
### Why typescript?
64+
65+
There are 3 types of GitHub Actions:
66+
67+
1. Docker Actions: They are slower than the others because they need to pull a Docker image.
68+
2. Composite Actions: They don't support [runs.post] to clean up the job after the action has run.
69+
We need this to revoke the token after the job is done.
70+
3. JavaScript Actions:
71+
- They are faster than Docker Actions because they don't require pulling a Docker image.
72+
- They support [runs.post] to clean up the job after the action has run.
73+
- GitHub provides the `@actions/core` library to easily set outputs and handle errors.
74+
75+
So we opted for a JavaScript Action.
76+
We use TypeScript to have type safety.
77+
78+
[runs.post]: https://docs.github.com/en/actions/sharing-automations/creating-actions/metadata-syntax-for-github-actions#runspost
79+
80+
### Why node 20?
81+
82+
We use Node 20 because it's the latest node version supported by GitHub Actions.
83+
The node version used by the action is defined in the `action.yml` file.

LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) The Rust Project Contributors
2+
3+
Permission is hereby granted, free of charge, to any
4+
person obtaining a copy of this software and associated
5+
documentation files (the "Software"), to deal in the
6+
Software without restriction, including without
7+
limitation the rights to use, copy, modify, merge,
8+
publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software
10+
is furnished to do so, subject to the following
11+
conditions:
12+
13+
The above copyright notice and this permission notice
14+
shall be included in all copies or substantial portions
15+
of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
18+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
21+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
24+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25+
DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)