|
| 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" |
0 commit comments