Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): move releasing to GitHub Actions MONGOSH-1871 #2309

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e2d6ee5
WIP: individual publishing of packages
gagik Dec 10, 2024
f759846
use 2.3.7
gagik Dec 18, 2024
2296340
update package-lock.json and packages
gagik Dec 18, 2024
546574a
restore changes
gagik Dec 19, 2024
f71c326
wip
gagik Dec 19, 2024
dfa6d5c
switch to bump script
gagik Dec 30, 2024
f54e208
check if bump is necessary for installs
gagik Dec 30, 2024
b55f0e8
add publish-packages
gagik Dec 31, 2024
986305e
remove package.json changes
gagik Dec 31, 2024
7eab63a
Update .github/workflows/release-packages.yml
gagik Dec 31, 2024
b2335d9
fix removed compass skip
gagik Dec 31, 2024
871a99c
switch to use app token
gagik Dec 31, 2024
1cbc99a
use bump in install script
gagik Dec 31, 2024
7d5b099
remove bump step
gagik Dec 31, 2024
908ec91
align with future release move changes
gagik Jan 6, 2025
9f4b462
fix naming
gagik Jan 6, 2025
a0c7dee
re-add bump
gagik Jan 6, 2025
723dff1
use npx and use tags in all cases
gagik Jan 8, 2025
2a569ce
use monorepo tools as dependency
gagik Jan 8, 2025
f5bd303
remove bump, use version
gagik Jan 8, 2025
5ffec0d
use a shell-api constant and switch to 2.3.8
gagik Jan 10, 2025
0df1e98
set all packages to 2.3.8
gagik Jan 10, 2025
b9a1726
revert to dev version
gagik Jan 10, 2025
4fa2164
use 2.3.8
gagik Jan 10, 2025
75bc72d
fix tests and match with mongosh --version
gagik Jan 10, 2025
0feeebe
add bumping
gagik Jan 2, 2025
25df857
WIP: move parts of release to GitHub Actions
gagik Jan 6, 2025
68f93dd
use publish
gagik Jan 6, 2025
a6e3cbe
remove no-tagging
gagik Jan 6, 2025
fb65c9a
add setting release publisher to the publish step
gagik Jan 14, 2025
f220798
add spaces
gagik Jan 14, 2025
f62b2a8
set the release submitter papertrail in evergreen
gagik Jan 14, 2025
837e516
add papertrail submitter from package.json
gagik Jan 14, 2025
e880d36
feat: update docs, remove triggers, requrie publisher, use tag-based …
gagik Jan 14, 2025
68c0e09
refactor(ci): use more object-oriented structure during publishing an…
gagik Jan 16, 2025
233a4b4
fix(ci): use path.join to fix cross-platform test failures
gagik Jan 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 38 additions & 18 deletions .evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4228,34 +4228,54 @@ functions:
papertrail_trace:
- command: shell.exec
params:
env:
PAPERTRAIL_KEY_ID: ${papertrail_key_id}
PAPERTRAIL_SECRET_KEY: ${papertrail_secret_key}
EVERGREEN_TASK_ID: ${task_id}
EVERGREEN_EXECUTION: ${execution}
EVERGREEN_AUTHOR: ${author}
working_dir: src
shell: bash
script: |
set -e
set -x
ls -lh dist/
if [ x"${triggered_by_git_tag}" == x"" ]; then
tag=$(git describe --tags --always --dirty)
else
tag="${triggered_by_git_tag}"
fi
echo "Setting version for papertrail to $tag, with product ${product}"
version="$(echo $tag | sed -e 's/^[vr]//')"
cat <<EOT > trace-expansions.yml
release_version: "$version"
EOT
cat trace-expansions.yml
- command: expansions.update
params:
file: src/trace-expansions.yml
- command: papertrail.trace
params:
key_id: ${papertrail_key_id}
secret_key: ${papertrail_secret_key}
product: ${product}
version: ${release_version}
filenames:
- "src/dist/*"

# Set the release publisher
submitter=$(node -p 'JSON.parse(fs.readFileSync("packages/cli-repl/package.json")).releasePublisher')
if [ -z "$submitter" ] || [ "$submitter" == "undefined" ] || [ "$submitter" == "null" ]; then
submitter="${EVERGREEN_AUTHOR}"
fi

echo "Setting version for papertrail to $tag, with product ${product} and submitter ${submitter}"

echo "X-PAPERTRAIL-KEY-ID: ${PAPERTRAIL_KEY_ID}" > .papertrail.headers
echo "X-PAPERTRAIL-SECRET-KEY: ${PAPERTRAIL_SECRET_KEY}" >> .papertrail.headers


for file in src/dist/* ; do
if [ -f "$file" ]; then
filename=$(basename "$file")
checksum=$(shasum -a 256 "$file" | cut -f1 -d' ')
platform="evergreen"
build="${EVERGREEN_TASK_ID}_${EVERGREEN_EXECUTION}"

curl -G -X POST -H @.papertrail.headers "https://papertrail.devprod-infra.prod.corp.mongodb.com/trace" \
--data-urlencode "version=${release_version}" \
--data-urlencode "product=${product}" \
--data-urlencode "sha256=${checksum}" \
--data-urlencode "filename=${filename}" \
--data-urlencode "build=${build}" \
--data-urlencode "platform=${platform}" \
--data-urlencode "submitter=${submitter}"
fi
done

rm -f .papertrail.headers

release_draft:
- command: expansions.write
Expand Down
55 changes: 38 additions & 17 deletions .evergreen/evergreen.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -873,34 +873,55 @@ functions:
papertrail_trace:
- command: shell.exec
params:
env:
PAPERTRAIL_KEY_ID: ${papertrail_key_id}
PAPERTRAIL_SECRET_KEY: ${papertrail_secret_key}
EVERGREEN_TASK_ID: ${task_id}
EVERGREEN_EXECUTION: ${execution}
EVERGREEN_AUTHOR: ${author}
working_dir: src
shell: bash
script: |
set -e
echo "X-PAPERTRAIL-KEY-ID: ${PAPERTRAIL_KEY_ID}" > .papertrail.headers
echo "X-PAPERTRAIL-SECRET-KEY: ${PAPERTRAIL_SECRET_KEY}" >> .papertrail.headers

set -x
ls -lh dist/
if [ x"${triggered_by_git_tag}" == x"" ]; then
tag=$(git describe --tags --always --dirty)
else
tag="${triggered_by_git_tag}"
fi
echo "Setting version for papertrail to $tag, with product ${product}"
version="$(echo $tag | sed -e 's/^[vr]//')"
cat <<EOT > trace-expansions.yml
release_version: "$version"
EOT
cat trace-expansions.yml
- command: expansions.update
params:
file: src/trace-expansions.yml
- command: papertrail.trace
params:
key_id: ${papertrail_key_id}
secret_key: ${papertrail_secret_key}
product: ${product}
version: ${release_version}
filenames:
- "src/dist/*"

# Set the release publisher
submitter=$(node -p 'JSON.parse(fs.readFileSync("packages/cli-repl/package.json")).releasePublisher')
if [ -z "$submitter" ] || [ "$submitter" == "undefined" ] || [ "$submitter" == "null" ]; then
echo "Using evergreen author as submitter"
submitter="${EVERGREEN_AUTHOR}"
fi

echo "Setting version for papertrail to $tag, with product ${product} and submitter ${submitter}"

for file in src/dist/* ; do
if [ -f "$file" ]; then
filename=$(basename "$file")
checksum=$(shasum -a 256 "$file" | cut -f1 -d' ')
platform="evergreen"
build="${EVERGREEN_TASK_ID}_${EVERGREEN_EXECUTION}"

curl -G -X POST -H @.papertrail.headers "https://papertrail.devprod-infra.prod.corp.mongodb.com/trace" \
--data-urlencode "version=${release_version}" \
--data-urlencode "product=${product}" \
--data-urlencode "sha256=${checksum}" \
--data-urlencode "filename=${filename}" \
--data-urlencode "build=${build}" \
--data-urlencode "platform=${platform}" \
--data-urlencode "submitter=${submitter}"
fi
done

rm -f .papertrail.headers

release_draft:
- command: expansions.write
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/merge-release-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Merge mongosh Release PR

on:
push:
tags:
- 'v*'

jobs:
prepare-release:
runs-on: ubuntu-latest
steps:
- uses: mongodb-js/devtools-shared/actions/setup-bot-token@main
id: app-token
with:
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}

- uses: actions/checkout@v4
with:
# don't checkout a detatched HEAD
ref: ${{ github.head_ref }}

# this is important so git log can pick up on
# the whole history to generate the list of AUTHORS
fetch-depth: "0"
token: ${{ steps.app-token.outputs.token }}


- name: Merge Pull Request
shell: bash
env:
MONGOSH_RELEASE_VERSION: ${{ env.NEXT_VERSION }}
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
gh pr merge release/${{ github.ref_name }} --squash
112 changes: 112 additions & 0 deletions .github/workflows/prepare-release-mongosh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Prepare mongosh Release

on:
workflow_dispatch:
inputs:
jiraTicket:
description: 'Jira ticket for the release, e.g. MONGOSH-1234'
required: true

versionBump:
description: 'Version bump'
type: choice
required: true
default: 'patch'
options:
- patch
- minor
- major
- exact-version

exactVersion:
description: 'Exact version: (Only effective selecting "exact-version" as version bump)'
required: false

jobs:
prepare-release:
runs-on: ubuntu-latest
steps:
- uses: mongodb-js/devtools-shared/actions/setup-bot-token@main
id: app-token
with:
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}

- uses: actions/checkout@v4
with:
# don't checkout a detatched HEAD
ref: ${{ github.head_ref }}

# this is important so git log can pick up on
# the whole history to generate the list of AUTHORS
fetch-depth: "0"
token: ${{ steps.app-token.outputs.token }}

- name: Setup Node.js Environment
uses: actions/setup-node@v4
with:
node-version: 20.18.1

- name: Determine Next Version
shell: bash
run: |
set -e

VERSION_BUMP=${{ github.event.inputs.versionBump }}

if [[ "$VERSION_BUMP" == "major" || "$VERSION_BUMP" == "minor" || "$VERSION_BUMP" == "patch" ]]; then
PREV_VERSION_TAG=$(gh api repos/:owner/:repo/releases --jq '. | map(select(.draft == false)) | .[0] | .tag_name')
PREV_VERSION=$(npx semver --coerce ${PREV_VERSION_TAG})

NEXT_VERSION=$(npx semver -i $VERSION_BUMP $PREV_VERSION)
else
NEXT_VERSION=${{ github.event.inputs.exactVersion }}
fi

# Remove the 'v' prefix from NEXT_VERSION if it exists
NEXT_VERSION="${NEXT_VERSION#v}"

# Validates the version before using it
npx semver v"${NEXT_VERSION}"

echo "RELEASE_TAG=v${NEXT_VERSION}" >> "$GITHUB_ENV"

- name: Validate release tag
shell: bash
run: |
if [ -z "${RELEASE_TAG}" ]; then
echo "RELEASE_TAG is not set or is empty"
exit 1
fi

if git rev-parse "$RELEASE_TAG" >/dev/null 2>&1; then
echo "Error: Tag $RELEASE_TAG already exists"
echo "If you are trying to re-create a draft release with this version, please delete the release and the tag first."
echo "If this version has already been release consider using a different one."
exit 1
fi

- name: Bump mongosh and package versions
shell: bash
env:
MONGOSH_RELEASE_VERSION: ${{ env.NEXT_VERSION }}
run: |
set -e
echo Bumping mongosh versions to ${NEXT_VERSION} and packages

npm run bump

git add .
git commit --no-allow-empty -m "chore(release): prepare for mongosh v${NEXT_VERSION} ${{ github.event.inputs.jiraTicket }}" || true

- name: Create Pull Request
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # 7.0.5
with:
token: ${{ steps.app-token.outputs.token }}
commit-message: "chore(release): prepare for mongosh v${NEXT_VERSION} ${{ github.event.inputs.jiraTicket }}"
branch: release/${RELEASE_TAG}
title: "chore(release): prepare for mongosh v${NEXT_VERSION} ${{ github.event.inputs.jiraTicket }}"
body: |
- [${{ github.event.inputs.jiraTicket }}](https://jira.mongodb.org/browse/${{ github.event.inputs.jiraTicket }})
- This PR is for the release of mongosh v${NEXT_VERSION}.
- **Do not merge manually, use the Release mongosh action instead.**
61 changes: 61 additions & 0 deletions .github/workflows/release-mongosh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Release mongosh
on:
workflow_run:
workflows: ["CheckQL", "Run Smoke Tests", "evergreen"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if evergreen is considered a workflow since it seems to be created by a bot/integration(?). Could leave and see what happens or just make it manual-only

types: ["completed"]
branches: ["release/**"]
workflow_dispatch:

jobs:
publish:
if: |
startsWith(github.head_ref, 'refs/heads/release/')
runs-on: ubuntu-latest

steps:
- uses: mongodb-js/devtools-shared/actions/setup-bot-token@main
id: app-token
with:
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}

- uses: actions/checkout@v4
with:
# don't checkout a detatched HEAD
ref: ${{ github.head_ref }}

# this is important so git log can pick up on
# the whole history to generate the list of AUTHORS
fetch-depth: "0"
token: ${{ steps.app-token.outputs.token }}

- name: Extract version from the branch
run: |
set -e
export NEXT_VERSION=$(echo "${GITHUB_REF}" | sed -n 's/refs\/heads\/release\/\(.*\)/\1/p')

echo "NEXT_VERSION=${NEXT_VERSION}" >> "$GITHUB_ENV"
echo "RELEASE_TAG=v${NEXT_VERSION}" >> "$GITHUB_ENV"

- name: Validate release tag
shell: bash
run: |
if [ -z "${RELEASE_TAG}" ]; then
echo "RELEASE_TAG is not set or is empty"
exit 1
fi

if git rev-parse "$RELEASE_TAG" >/dev/null 2>&1; then
echo "Error: Tag $RELEASE_TAG already exists"
echo "If you are trying to re-create a draft release with this version, please delete the release and the tag first."
echo "If this version has already been released consider using a different one."
exit 1
fi

- name: "Trigger mongosh publish"
env:
NPM_TOKEN: ${{ secrets.DEVTOOLSBOT_NPM_TOKEN }}
MONGOSH_RELEASE_PUBLISHER: ${{ github.triggering_actor }}
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc
npm run publish
Loading
Loading