Skip to content

Commit e683098

Browse files
authored
Add create release branch action (#59)
1 parent 346b4d6 commit e683098

File tree

3 files changed

+165
-2
lines changed

3 files changed

+165
-2
lines changed

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,44 @@ By default, all files in the S3 directory are uploaded. When the `dry_run` input
255255
is set to anything other than `false`, no files are uploaded, but instead the
256256
filename along with the resulting location in the bucket is printed.
257257

258+
## Create Release Branch
259+
260+
Use this action to create a release branch and populate it with metadata.
261+
It will create a new Silk Asset Group, update the SBOM-lite file,
262+
update the ``SILK_ASSET_GROUP`` and ``EVERGREEN_PROJECT`` env variables
263+
in the release workflow file, bump the version to a
264+
prerelease version, and push the changes.
265+
266+
> [!Note]
267+
> You will need to wait overnight before making a release on
268+
> the new branch to allow Silk to be populated, so it is recommended to
269+
> make a minor/major release prior to creating a release branch, or create the
270+
> release branch at least one day before a planned release.
271+
272+
```yaml
273+
- name: Setup
274+
uses: mongodb-labs/drivers-github-tools/setup@v2
275+
with:
276+
...
277+
278+
- name: Create Release Branch
279+
uses: mongodb-labs/drivers-github-tools/create-branch@v2
280+
with:
281+
# user inputs
282+
branch: ...
283+
version: ...
284+
base_ref: <optional>
285+
push_changes: <whether to push changes>
286+
# other inputs
287+
version_bump_script: <path/to/version/bump/script>
288+
evergreen_project: <name of evergreen release project>
289+
```
290+
258291
## Python Helper Scripts
259292

260293
These scripts are opinionated helper scripts for Python releases.
261294

262-
### Bump and Tag
295+
### Pre-Publish
263296

264297
Bump the version and create a new tag. Verify the tag.
265298
Push the commit and tag to the source branch unless `dry_run` is set.
@@ -270,7 +303,7 @@ Push the commit and tag to the source branch unless `dry_run` is set.
270303
with:
271304
...
272305
273-
- uses: mongodb-labs/drivers-github-tools/python/bump-and-tag@v2
306+
- uses: mongodb-labs/drivers-github-tools/python/pre-publishv2
274307
with:
275308
version: ${{ inputs.version }}
276309
version_bump_script: ./.github/scripts/bump-version.sh

create-branch/action.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Create Release Branch
2+
description: Create a release branch and update branch metadata
3+
inputs:
4+
# User provided inputs.
5+
branch_name:
6+
description: The name of the new branch
7+
required: true
8+
version:
9+
description: The version to set on the branch
10+
required: true
11+
base_ref:
12+
description: The base reference for the branch
13+
push_changes:
14+
description: Whether to push the changes
15+
default: "true"
16+
# Workflow provided inputs.
17+
version_bump_script:
18+
description: The script used to bump the version
19+
required: true
20+
evergreen_project:
21+
description: The name of the evergreen project for the new branch
22+
required: true
23+
release_workflow_path:
24+
description: The path to the release workflow file
25+
default: .github/workflows/release.yml
26+
sbom_file_path:
27+
description: The path of the sbom-lite file
28+
default: sbom.json
29+
silk_group_prefix:
30+
description: The prefix to use for the silk asset group, defaults to the repo name
31+
artifactory_image:
32+
description: Image to use for artifactory
33+
default: artifactory.corp.mongodb.com/release-tools-container-registry-public-local
34+
35+
runs:
36+
using: composite
37+
steps:
38+
- name: Create a release branch and update branch metadata
39+
shell: bash
40+
env:
41+
BRANCH: ${{ inputs.branch_name }}
42+
BASE_REF: ${{ inputs.base_ref }}
43+
SBOM_FILE_PATH: ${{ inputs.sbom_file_path }}
44+
RELEASE_WORKFLOW_PATH: ${{ inputs.release_workflow_path }}
45+
EVERGREEN_PROJECT: ${{ inputs.evergreen_project }}
46+
SILK_PREFIX: ${{ inputs.silk_group_prefix }}
47+
ARTIFACTORY_IMAGE: ${{ inputs.artifactory_image }}
48+
run: ${{ github.action_path }}/create-branch.sh
49+
- uses: mongodb-labs/drivers-github-tools/bump-version@v2
50+
with:
51+
version: ${{ inputs.version }}
52+
version_bump_script: ${{ inputs.version_bump_script }}
53+
commit_template: "Prep branch ${{ inputs.branch_name }}"
54+
push_commit: ${{ inputs.push_changes }}

create-branch/create-branch.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#! /bin/bash
2+
set -eu
3+
4+
echo "Create or checkout the branch."
5+
OWNER_REPO="${GITHUB_REPOSITORY}"
6+
git ls-remote --exit-code --heads https://github.com/${OWNER_REPO}.git refs/heads/$BRANCH || {
7+
git branch $BRANCH $BASE_REF
8+
}
9+
git fetch origin $BRANCH || true
10+
git checkout $BRANCH
11+
12+
echo "Get silk creds."
13+
# shellcheck disable=SC2046
14+
export $(grep -v '^#' $SILKBOMB_ENVFILE | xargs -0)
15+
16+
echo "Get a silk token."
17+
SILK_JWT_TOKEN=$(curl -s -X POST "https://silkapi.us1.app.silk.security/api/v1/authenticate" \
18+
-H "accept: application/json" -H "Content-Type: application/json" \
19+
-d '{ "client_id": "'${SILK_CLIENT_ID}'", "client_secret": "'${SILK_CLIENT_SECRET}'" }' \
20+
| jq -r '.token')
21+
22+
echo "Get the silk asset group prefix."
23+
if [ -z "${SILK_PREFIX:-}" ]; then
24+
REPO="${OWNER_REPO##*/}"
25+
SILK_PREFIX=${REPO}
26+
fi
27+
SILK_GROUP="${SILK_PREFIX}-${BRANCH}"
28+
29+
echo "Create the silk asset group."
30+
json_payload=$(cat <<EOF
31+
{
32+
"active": true,
33+
"name": "${SILK_GROUP}",
34+
"code_repo_url": "https://github.com/${OWNER_REPO}",
35+
"branch": "${BRANCH}",
36+
"metadata": {
37+
"sbom_lite_path": "${SBOM_FILE_PATH}"
38+
},
39+
"file_paths": [],
40+
"asset_id": "$SILK_GROUP"
41+
}
42+
EOF
43+
)
44+
curl -X 'POST' \
45+
'https://silkapi.us1.app.silk.security/api/v1/raw/asset_group' \
46+
-H "accept: application/json" -H "Authorization: ${SILK_JWT_TOKEN}" \
47+
-H 'Content-Type: application/json' \
48+
-d "$json_payload"
49+
50+
echo "SILK_ASSET_GROUP=$SILK_GROUP" >> $GITHUB_STEP_SUMMARY
51+
52+
echo "Create a temp sbom."
53+
TMP_SBOM=sbom-for-${BRANCH}.json
54+
podman run --platform="linux/amd64" --rm -v "$(pwd)":/pwd \
55+
${ARTIFACTORY_IMAGE}/silkbomb:1.0 \
56+
update --sbom-out /pwd/${TMP_SBOM}
57+
58+
echo "Get the new timestamp and serial number."
59+
set -x
60+
SERIAL=$(jq -r '.serialNumber' ${TMP_SBOM})
61+
TIMESTAMP=$(jq -r '.metadata.timestamp' ${TMP_SBOM})
62+
rm ${TMP_SBOM}
63+
64+
cat ${SBOM_FILE_PATH}
65+
echo "Replace the values in the existing sbom."
66+
cat <<< "$(jq --indent 4 '.serialNumber = "'${SERIAL}'"' ${SBOM_FILE_PATH})" > ${SBOM_FILE_PATH}
67+
cat <<< "$(jq --indent 4 '.metadata.timestamp = "'${TIMESTAMP}'"' ${SBOM_FILE_PATH})" > ${SBOM_FILE_PATH}
68+
cat ${SBOM_FILE_PATH}
69+
70+
echo "Update the workflow with the silk asset group and evergreen project."
71+
sed -i 's/SILK_ASSET_GROUP:.*/SILK_ASSET_GROUP: '${SILK_GROUP}'/' ${RELEASE_WORKFLOW_PATH}
72+
sed -i 's/EVERGREEN_PROJECT:.*/EVERGREEN_PROJECT: '${EVERGREEN_PROJECT}'/' ${RELEASE_WORKFLOW_PATH}
73+
74+
echo "Add the changed files."
75+
git --no-pager diff
76+
git add ${SBOM_FILE_PATH} ${RELEASE_WORKFLOW_PATH}

0 commit comments

Comments
 (0)