Skip to content

Commit a1f9615

Browse files
authored
Refactor Actions and Add Python-Specific Actions (#6)
1 parent 798f0de commit a1f9615

File tree

12 files changed

+412
-193
lines changed

12 files changed

+412
-193
lines changed

README.md

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

8+
## Setup
9+
10+
There is a common setup action that is meant to be run before all
11+
other actions. It handles fetching secrets from AWS Secrets Manager,
12+
signing into Artifactory, setting up Garasign credentials, and
13+
setting up environment variables used in other actions.
14+
The action requires `id-token: write` permissions.
15+
16+
```yaml
17+
- name: setup
18+
uses: mongodb/drivers-github-tools/setup@v2
19+
with:
20+
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
21+
aws_region_name: ${{ vars.AWS_REGION_NAME }}
22+
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
23+
```
24+
25+
> [!Note]
26+
> You *must* use the `actions/checkout` action prior to calling the `setup` action,
27+
> Since the `setup` action sets up git config that would be overridden by the
28+
> `actions/checkout action`
29+
830
## Signing tools
931

1032
The actions in the `garasign` folder are used to sign artifacts using the team's
@@ -15,78 +37,119 @@ GPG key.
1537
Use this action to create signed git artifacts:
1638

1739
```yaml
18-
- name: "Create signed commit"
19-
uses: mongodb/drivers-github-tools/garasign/git-sign@main
40+
- name: Setup
41+
uses: mongodb/drivers-github-tools/setup@v2
2042
with:
21-
command: "git commit -m 'Commit' -s --gpg-sign=${{ vars.GPG_KEY_ID }}"
22-
garasign_username: ${{ secrets.GRS_CONFIG_USER1_USERNAME }}
23-
garasign_password: ${{ secrets.GRS_CONFIG_USER1_PASSWORD }}
24-
artifactory_username: ${{ secrets.ARTIFACTORY_USER }}
25-
artifactory_password: ${{ secrets.ARTIFACTORY_PASSWORD }}
26-
27-
- name: "Create signed tag"
28-
uses: mongodb/drivers-github-tools/garasign/git-sign@main
29-
with:
30-
command: "git tag -m 'Tag' -s --local-user=${{ vars.GPG_KEY_ID }} <tag>"
31-
garasign_username: ${{ secrets.GRS_CONFIG_USER1_USERNAME }}
32-
garasign_password: ${{ secrets.GRS_CONFIG_USER1_PASSWORD }}
33-
artifactory_username: ${{ secrets.ARTIFACTORY_USER }}
34-
artifactory_password: ${{ secrets.ARTIFACTORY_PASSWORD }}
35-
skip_setup: true
36-
```
43+
...
3744
38-
If the action is used multiple times within the same job, the `skip_setup`
39-
option can be set to a truthy value to avoid unnecessary logins to artifactory.
45+
- name: Create signed commit
46+
uses: mongodb/drivers-github-tools/git-sign@v2
47+
48+
- name: Create signed tag
49+
uses: mongodb/drivers-github-tools/git-sign@v2
50+
```
4051

4152
### gpg-sign
4253

4354
This action is used to create detached signatures for files:
4455

4556
```yaml
46-
- name: "Create detached signature"
47-
uses: mongodb/drivers-github-tools/garasign/gpg-sign@main
57+
- name: Setup
58+
uses: mongodb/drivers-github-tools/setup@v2
59+
with:
60+
...
61+
62+
- name: Create detached signature
63+
uses: mongodb/drivers-github-tools/gpg-sign@v2
4864
with:
4965
filenames: somefile.ext
50-
garasign_username: ${{ secrets.GRS_CONFIG_USER1_USERNAME }}
51-
garasign_password: ${{ secrets.GRS_CONFIG_USER1_PASSWORD }}
52-
artifactory_username: ${{ secrets.ARTIFACTORY_USER }}
53-
artifactory_password: ${{ secrets.ARTIFACTORY_PASSWORD }}
5466
```
5567

5668
The action will create a signature file `somefile.ext.sig` in the working
5769
directory.
58-
If the action is used multiple times within the same job, the `skip_setup`
59-
option can be set to a truthy value to avoid unnecessary logins to artifactory.
6070

61-
You can also supply multiple space-separated filenames to sign a list of files:
71+
You can also supply a glob pattern to sign a group of files:
6272

6373
```yaml
64-
- name: "Create detached signature"
65-
uses: mongodb/drivers-github-tools/garasign/gpg-sign@main
74+
- name: Setup
75+
uses: mongodb/drivers-github-tools/setup@v2
76+
with:
77+
...
78+
79+
- name: Create detached signature
80+
uses: mongodb/drivers-github-tools/garasign/gpg-sign@v1
6681
with:
6782
filenames: dist/*
68-
garasign_username: ${{ secrets.GRS_CONFIG_USER1_USERNAME }}
69-
garasign_password: ${{ secrets.GRS_CONFIG_USER1_PASSWORD }}
70-
artifactory_username: ${{ secrets.ARTIFACTORY_USER }}
71-
artifactory_password: ${{ secrets.ARTIFACTORY_PASSWORD }}
7283
```
7384

7485
## Reporting tools
7586

7687
The following tools are meant to aid in generating Software Security Development Lifecycle
7788
reports associated with a product release.
7889

79-
### Papertrail
90+
### Authorized Publication
8091

8192
This action will create a record of authorized publication on distribution channels.
82-
By default it will create a "papertrail.txt" file in the current directory.
93+
It will create the file `$S3_ASSETS/authorized_publication.txt`
8394

8495
```yaml
85-
- name: "Create papertrail report"
86-
uses: mongodb/drivers-github-tools/papertrail@main
96+
- name: Setup
97+
uses: mongodb/drivers-github-tools/setup@v2
98+
with:
99+
...
100+
101+
- name: Create Authorized Publication Report
102+
uses: mongodb/drivers-github-tools/authorized-pub@v2
87103
with:
88104
product_name: Mongo Python Driver
89105
release_version: ${{ github.ref_name }}
90106
filenames: dist/*
91107
token: ${{ github.token }}
92108
```
109+
110+
## Python Helper Scripts
111+
112+
These scripts are opinionated helper scripts for Python releases.
113+
114+
### Bump and Tag
115+
116+
Bump the version and create a new tag. Verify the tag.
117+
Push the commit and tag to the source branch unless `dry_run` is set.
118+
119+
```yaml
120+
- name: Setup
121+
uses: mongodb/drivers-github-tools/setup@v2
122+
with:
123+
...
124+
125+
- uses: mongodb/drivers-github-tools/python/bump-and-tag@v2
126+
with:
127+
version: ${{ inputs.version }}
128+
version_bump_script: ./.github/scripts/bump-version.sh
129+
dry_run: ${{ inputs.dry_run }}
130+
```
131+
132+
### Publish
133+
134+
Handles tasks related to publishing Python packages, including
135+
signing `dist` file and publishing the `dist` files to PyPI.
136+
It will also push the following (dev) version to the source branch.
137+
It will create a draft GitHub release and attach the signature files.
138+
Finally, it will publish a report to the appropriate S3 bucket.
139+
If `dry_run` is set, nothing will be published or pushed.
140+
141+
```yaml
142+
- name: Setup
143+
uses: mongodb/drivers-github-tools/setup@v2
144+
with:
145+
...
146+
147+
- uses: mongodb-labs/drivers-github-tools/python/publish@v2
148+
with:
149+
version: ${{ inputs.version }}
150+
following_version: ${{ inputs.following_version }}
151+
version_bump_script: ./.github/scripts/bump-version.sh
152+
product_name: winkerberos
153+
token: ${{ github.token }}
154+
dry_run: ${{ inputs.dry_run }}
155+
```

authorized-pub/action.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Authorized Publication
2+
description: Generate report for authorized publication on distribution channels
3+
inputs:
4+
product_name:
5+
description: Name of product
6+
required: true
7+
release_version:
8+
description: The release version
9+
required: true
10+
filenames:
11+
description: Artifact filename(s) to include in the report, can be a glob pattern
12+
required: true
13+
token:
14+
description: The GitHub token for the action
15+
required: true
16+
17+
runs:
18+
using: composite
19+
steps:
20+
- name: Prepare report
21+
shell: bash
22+
run: |
23+
export GH_TOKEN=${{ inputs.token }}
24+
NAME=$(gh api users/${{ github.actor }} --jq '.name')
25+
export REPORT=$S3_ASSETS/authorized_publication.txt
26+
echo "Product: ${{ inputs.product_name }}" > $REPORT
27+
echo "Version: ${{ inputs.release_version }}" >> $REPORT
28+
echo "Releaser: $NAME" >> $REPORT
29+
echo "Build Source: GitHub Actions"
30+
echo "Build Number: ${{ github.run_id }}"
31+
for filename in ${{ inputs.filenames }}; do
32+
SHA=$(shasum -a 256 $filename | awk '{print $1;}')
33+
echo "Filename: $filename" >> $REPORT
34+
echo "Shasum: $SHA" >> $REPORT
35+
done

garasign/git-sign/action.yml

Lines changed: 0 additions & 58 deletions
This file was deleted.

garasign/gpg-sign/action.yml

Lines changed: 0 additions & 58 deletions
This file was deleted.

git-sign/action.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "Run git actions in a signing container"
2+
description: "Allows running arbitrary git actions in a container with GPG keys loaded"
3+
inputs:
4+
command:
5+
description: "Command to run inside the container"
6+
required: true
7+
artifactory_image:
8+
description: "Image to use for artifactory"
9+
default: release-tools-container-registry-local/garasign-git
10+
11+
runs:
12+
using: composite
13+
steps:
14+
- name: "Run git command"
15+
run: |
16+
podman run \
17+
--env-file=$GARASIGN_ENVFILE \
18+
--rm \
19+
-v $(pwd):$(pwd) \
20+
-w $(pwd) \
21+
${ARTIFACTORY_REGISTRY}/${{ inputs.artifactory_image }} \
22+
/bin/bash -c "gpgloader && ${{ inputs.command }}"
23+
shell: bash

gpg-sign/action.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: "Sign artifact(s) using garasign"
2+
description: "Signs release artifact(s)"
3+
inputs:
4+
filenames:
5+
description: "File name(s) to sign, can be a glob pattern"
6+
required: true
7+
artifactory_image:
8+
description: "Image to use for artifactory"
9+
default: release-tools-container-registry-local/garasign-gpg
10+
11+
runs:
12+
using: composite
13+
steps:
14+
- name: "Create detached signature for file"
15+
shell: bash
16+
run: |
17+
podman run \
18+
--env-file=$GARASIGN_ENVFILE \
19+
--rm \
20+
-v $(pwd):$(pwd) \
21+
-w $(pwd) \
22+
${ARTIFACTORY_REGISTRY}/${{ inputs.artifactory_image }} \
23+
/bin/bash -c 'gpgloader && for filename in ${{ inputs.filenames }}; do gpg --detach-sign --armor --output ${filename}.sig ${filename}; done'
24+
25+
- name: "Move the signature files to the release directory"
26+
shell: bash
27+
run: |
28+
mv ${{inputs.filenames}}.sig $RELEASE_ASSETS

0 commit comments

Comments
 (0)