Skip to content

Commit 1e0af6f

Browse files
authored
Add secure checkout action (#31)
1 parent b5521e6 commit 1e0af6f

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
66
This repository contains GitHub Actions that are common to drivers.
77

8+
## Secure Checkout
9+
10+
This action will perform a checkout with the GitHub App credentials.
11+
12+
```yaml
13+
- name: secure-checkout
14+
uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
15+
with:
16+
app_id: ${{ vars.APP_ID }}
17+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
18+
```
19+
20+
By default it will use the current `${{github.ref}}` if the `ref` parameter is
21+
not given. It will write the secure global variable `GH_TOKEN` that can be
22+
used with the `gh` cli.
23+
24+
825
## Setup
926

1027
There is a common setup action that is meant to be run before all

secure-checkout/action.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Secure Checkout
2+
description: Secure Checkout with GitHub App Credentials
3+
inputs:
4+
app_id:
5+
description: The ID of the GitHub app.
6+
required: true
7+
private_key:
8+
description: The private key of the GitHub app.
9+
required: true
10+
ref:
11+
description: The reference to check out
12+
default: ${{ github.ref }}
13+
fetch-depth:
14+
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.'
15+
default: "1"
16+
submodules:
17+
description: >
18+
Whether to checkout submodules: `true` to checkout submodules or `recursive` to
19+
recursively checkout submodules.
20+
default: "false"
21+
22+
runs:
23+
using: composite
24+
steps:
25+
- name: Create temporary app token
26+
uses: actions/create-github-app-token@v1
27+
id: app-token
28+
with:
29+
app-id: ${{ inputs.app_id }}
30+
private-key: ${{ inputs.private_key }}
31+
32+
- name: Store GitHub token in environment
33+
run: echo "GH_TOKEN=${{ steps.app-token.outputs.token }}" >> "$GITHUB_ENV"
34+
shell: bash
35+
36+
- uses: actions/checkout@v4
37+
with:
38+
ref: ${{ inputs.ref }}
39+
token: ${{ env.GH_TOKEN }}
40+
fetch-depth: ${ {inputs.fetch-depth }}
41+
submodules: ${{ inputs.submodules }}

0 commit comments

Comments
 (0)