Skip to content

Commit

Permalink
CLOUDP-268278 Automate documentation update with Copybara (#3265)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmenezes authored Sep 23, 2024
1 parent db32f99 commit ff37c6c
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 15 deletions.
54 changes: 54 additions & 0 deletions build/ci/copy.bara.sky.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
Copy definitions
"""

release_tag = "${TAG}"
source_url = "https://github.com/mongodb/mongodb-atlas-cli.git"
destination_url = "https://github.com/10gen/cloud-docs.git"
destination_url_cli_docs = "https://github.com/mongodb/docs-atlas-cli.git"
author = "apix-bot[bot] <168195273+apix-bot[bot]@users.noreply.github.com>"

core.workflow(
name = "cloud-docs",
origin = git.origin(
url = source_url,
ref = release_tag,
),
destination = git.github_pr_destination(
url = destination_url,
destination_ref = "master",
pr_branch = "apix_bot_copybara_pull_request_"+release_tag,
title = "Copies Atlas CLI commands for release tag: " + release_tag,
body = "Copies Atlas CLI commands from the source repo. See the attached Netlify comment for build log and staging.",
integrates = [],
),
origin_files = glob(["docs/command/**"], exclude = ["docs/command/atlas-completion**"]),
destination_files = glob(["source/includes/command/**"]),
authoring = authoring.pass_thru(author),
transformations = [
core.move("docs/command", "source/includes/command"),
core.rename(".txt", ".rst", suffix = True)
],
)

core.workflow(
name = "docs-atlas-cli",
origin = git.origin(
url = source_url,
ref = release_tag,
),
destination = git.github_pr_destination(
url = destination_url_cli_docs,
destination_ref = "master",
pr_branch = "apix_bot_copybara_pull_request_"+release_tag,
title = "Copies Atlas CLI commands for release tag: " + release_tag,
body = "Copies Atlas CLI commands from the source repo. See the attached Netlify comment for build log and staging.",
integrates = [],
),
origin_files = glob(["docs/command/**"]),
destination_files = glob(["source/command/**"]),
authoring = authoring.pass_thru(author),
transformations = [
core.move("docs/command", "source/command"),
],
)
11 changes: 8 additions & 3 deletions build/ci/evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ variables:
<<: *go_env
pre:
- func: "clone"
- func: "set-expansions"
post:
- command: attach.xunit_results
params:
Expand Down Expand Up @@ -401,14 +402,18 @@ functions:
sleep 10
done
shell: bash
"set-home":
"set-expansions":
- command: shell.exec
params:
<<: *go_options
shell: bash
script: |
set -Eeou pipefail
echo "home: $HOME" > expansions.yaml
cat <<EOF > expansions.yaml
home: $HOME
tag: $(git tag --list 'atlascli/v*' --sort=-taggerdate | head -1)
version: $(git tag --list 'atlascli/v*' --sort=-taggerdate | head -1 | cut -d 'v' -f 2)
EOF
- command: expansions.update
params:
ignore_missing_file: true
Expand Down Expand Up @@ -1575,8 +1580,8 @@ tasks:
task_groups:
- name: atlas_deployments_windows_group
setup_task:
- func: "set-home"
- func: clone
- func: "set-expansions"
- func: "vendor deps"
- func: "install terraform"
- func: "install azure cli"
Expand Down
74 changes: 72 additions & 2 deletions build/ci/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ functions:
<<: *go_options
binary: build/package/generate-notices.sh
"package":
- command: github.generate_token
params:
expansion_name: github_token
- command: subprocess.exec
type: test
params:
Expand All @@ -81,15 +84,14 @@ functions:
ARTIFACTORY_PASSWORD: ${artifactory_password}
GRS_USERNAME: ${garasign_username}
GRS_PASSWORD: ${garasign_password}
GITHUB_TOKEN: ${github_token}
include_expansions_in_env:
- go_base_path
- workdir
- notary_service_key_id
- notary_service_secret
- notary_service_url
- goreleaser_key
- github_app_id
- github_app_pem
- unstable
binary: build/package/package.sh
"install go-msi":
Expand Down Expand Up @@ -256,6 +258,41 @@ functions:
- mongo_repo
working_dir: src/github.com/mongodb/mongodb-atlas-cli/build/package/docker/repo
binary: ./docker-build.sh
"build-copybara":
- command: subprocess.exec
params:
<<: *go_options
binary: git
args:
- clone
- --depth=1
- https://github.com/google/copybara
- ${workdir}/copybara
- command: subprocess.exec
params:
<<: *go_options
binary: docker
args:
- build
- -t
- google/copybara
- ${workdir}/copybara
"run-copybara":
- command: shell.exec
params:
<<: *go_options
env:
<<: *go_env
TAG: ${tag}
GH_TOKEN: ${gh_token}
WORKFLOW: ${workflow}
EVERGREEN_USER: ${evergreen_user}
EVERGREEN_API_KEY: ${evergreen_api_key}
DOCS_SLACK_CHANNEL: ${docs_slack_channel}
working_dir: src/github.com/mongodb/mongodb-atlas-cli/build/ci
shell: bash
script: |
./run-copybara.sh
tasks:
- name: package_msi
tags: ["packaging"]
Expand Down Expand Up @@ -419,6 +456,30 @@ tasks:
- func: "powershell build"
vars:
file: windows_post_package_test
- name: copybara
depends_on:
- name: package_goreleaser
variant: release_atlascli_github
commands:
- func: "build-copybara"
- command: github.generate_token
params:
expansion_name: docs_atlas_cli_token
owner: mongodb
repo: docs-atlas-cli
- func: "run-copybara"
vars:
gh_token: ${docs_atlas_cli_token}
workflow: docs-atlas-cli
- command: github.generate_token
params:
expansion_name: cloud_docs_token
owner: 10gen
repo: cloud-docs
- func: "run-copybara"
vars:
gh_token: ${cloud_docs_token}
workflow: cloud-docs
buildvariants:
- name: go_atlascli_msi_snapshot
display_name: "Packaging AtlasCLI (go-msi)"
Expand Down Expand Up @@ -469,6 +530,15 @@ buildvariants:
depends_on:
- name: package_msi
variant: release_atlascli_msi
- name: copybara
display_name: "Copybara"
git_tag_only: true
run_on:
- ubuntu2404-small
expansions:
<<: *go_linux_version
tasks:
- name: copybara
- name: release_atlascli_msi
display_name: "Release AtlasCLI (go-msi)"
run_on:
Expand Down
82 changes: 82 additions & 0 deletions build/ci/run-copybara.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash

# Copyright 2024 MongoDB Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -Eeou pipefail

if [[ "${TAG:?}" == "" ]]; then
echo "missing \$TAG"
exit 1
fi

if [[ "${GH_TOKEN:?}" == "" ]]; then
echo "missing \$GH_TOKEN"
exit 1
fi

if [[ "${WORKFLOW:?}" == "" ]]; then
echo "missing \$WORKFLOW"
exit 1
fi

if [[ "${EVERGREEN_USER:?}" == "" ]]; then
echo "missing \$EVERGREEN_USER"
exit 1
fi

if [[ "${EVERGREEN_API_KEY:?}" == "" ]]; then
echo "missing \$EVERGREEN_API_KEY"
exit 1
fi

if [[ "${DOCS_SLACK_CHANNEL:?}" == "" ]]; then
echo "missing \$DOCS_SLACK_CHANNEL"
exit 1
fi

cat <<EOF > .gitconfig
[user]
name = apix-bot[bot]
email = 168195273+apix-bot[bot]@users.noreply.github.com
[credential]
helper = store
EOF

envsubst < copy.bara.sky.template > copy.bara.sky

echo "https://x-access-token:${GH_TOKEN:?}@github.com" > .git-credentials
echo "https://x-access-token:${GH_TOKEN:?}@api.github.com" >> .git-credentials

docker run \
--name copybara-container \
-v "${PWD}:/usr/src/app" \
-v "${PWD}/.gitconfig:/root/.gitconfig" \
-v "${PWD}/.git-credentials:/root/.git-credentials" \
-e "COPYBARA_WORKFLOW=$WORKFLOW" \
-e "COPYBARA_OPTIONS=--github-api-bearer-auth true" \
google/copybara

PR_URL=$(docker logs copybara-container 2>&1 | grep "/pull/" | sed -E 's/^.*(https\:[^\ ]+).*$/\1/')

rm -rf .git-credentials .gitconfig copy.bara.sky
docker rm -f copybara-container

TARGET="$DOCS_SLACK_CHANNEL"
MSG="Hey team :wave: ${PR_URL} is ready for review :thankyou:"
echo "{\"target\":\"$TARGET\",\"msg\":\"$MSG\"}"
curl --header "Api-User:${EVERGREEN_USER:?}" \
--header "Api-Key:${EVERGREEN_API_KEY:?}" \
--request POST "https://evergreen.mongodb.com/rest/v2/notifications/slack" \
--data "{\"target\":\"$TARGET\",\"msg\":\"$MSG\"}"
10 changes: 0 additions & 10 deletions build/package/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,12 @@
set -Eeou pipefail

export GOROOT="${GOROOT:?}"
export GITHUB_APP_ID=${github_app_id:?}
export GITHUB_APP_PEM=${github_app_pem:?}
export NOTARY_SERVICE_URL=${notary_service_url:?}
export MACOS_NOTARY_KEY=${notary_service_key_id:?}
export MACOS_NOTARY_SECRET=${notary_service_secret:?}
export GORELEASER_KEY=${goreleaser_key:?}
export VERSION_GIT

echo "$GITHUB_APP_PEM" > app.pem
GITHUB_INSTALLATION_ID=$(gh-token installations --app-id "$GITHUB_APP_ID" --key ./app.pem | jq '.[] | select(.account.login == "mongodb") | .id' | head -1)
GITHUB_TOKEN=$(gh-token generate --app-id "$GITHUB_APP_ID" --key ./app.pem --installation-id "$GITHUB_INSTALLATION_ID" -t)
rm -rf app.pem
export GITHUB_TOKEN

VERSION_GIT="$(git tag --list "atlascli/v*" --sort=taggerdate | tail -1 | cut -d "v" -f 2)"

if [[ "${unstable-}" == "-unstable" ]]; then
Expand All @@ -41,8 +33,6 @@ else
./bin/goreleaser --config "build/package/.goreleaser.yml" --clean --release-notes "CHANGELOG.md" -p 1
fi

gh-token revoke -t "$GITHUB_TOKEN"

# check that the notarization service signed the mac binaries
SIGNED_FILE_NAME=mongodb-atlas-cli_macos_signed.zip
if [[ -f "dist/$SIGNED_FILE_NAME" ]]; then
Expand Down

0 comments on commit ff37c6c

Please sign in to comment.