Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PrivateStorageio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PrivateStorage
PrivateStorageio
Commits
9d290620
Commit
9d290620
authored
Jul 22, 2022
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
first attempt at develop-to-production merge bot
parent
5f532577
Branches
Branches containing commit
No related tags found
2 merge requests
!328
update production
,
!318
Automatically create production update MRs
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitlab-ci.yml
+10
-0
10 additions, 0 deletions
.gitlab-ci.yml
ci-tools/update-production
+87
-0
87 additions, 0 deletions
ci-tools/update-production
with
97 additions
and
0 deletions
.gitlab-ci.yml
+
10
−
0
View file @
9d290620
...
...
@@ -167,3 +167,13 @@ update-nixpkgs:
"$CI_PROJECT_PATH" \
"$CI_PROJECT_ID" \
"$CI_DEFAULT_BRANCH"
update-production
:
<<
:
*RUN_ON_MERGE_REQUEST
script
:
-
|
./ci-tools/update-production \
"$CI_SERVER_URL" \
"$CI_PROJECT_ID" \
"develop" \
"production
This diff is collapsed.
Click to expand it.
ci-tools/update-production
0 → 100644
+
87
−
0
View file @
9d290620
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p git curl
set -eux -o pipefail
main() {
local TOKEN=$1
shift
local SERVER_URL=$1
shift
local PROJECT_ID=$1
shift
local SOURCE_BRANCH=$1
shift
local TARGET_BRANCH=$1
shift
# If there have been no changes we'll just abandon this update.
ensure_changes "$SOURCE_BRANCH" "$TARGET_BRANCH"
local NOTES=$(compute_notes_diff "$SOURCE_BRANCH" "$TARGET_BRANCH")
create_merge_request "$TOKEN" "$SERVER_URL" "$PROJECT_ID" "$SOURCE_BRANCH" "$TARGET_BRANCH" "$NOTES"
}
ensure_changes() {
local SOURCE_BRANCH=$1
shift
local TARGET_BRANCH=$1
shift
if [ $(git rev-parse "$SOURCE_BRANCH") -eq $(git rev-parse "$TARGET_BRANCH") ]; then
echo "No changes."
exit 0
fi
}
compute_notes_diff() {
local SOURCE_BRANCH=$1
shift
local TARGET_BRANCH=$1
shift
git diff origin/"$SOURCE_BRANCH"...origin/"$TARGET_BRANCH" -- DEPLOYMENT-NOTES.rst
}
create_merge_request() {
local TOKEN=$1
shift
local SERVER_URL=$1
shift
local PROJECT_ID=$1
shift
# THe source branch of the MR.
local SOURCE_BRANCH=$1
shift
# The target branch of the MR.
local TARGET_BRANCH=$1
shift
local NOTES=$1
shift
local BODY=$(python3 -c '
import sys, json
print(json.dumps({
"id": sys.argv[1],
"source_branch": sys.argv[2],
"target_branch": sys.argv[3],
"remove_source_branch": True,
"title": f"update {sys.argv[3]}",
"description": f"```diff\n{sys.argv[4]}\n```",
}))
' "$PROJECT_ID" "$SOURCE_BRANCH" "$TARGET_BRANCH" "$NOTES")
curl --verbose -X POST --data "${BODY}" --header "Content-Type: application/json" --header "PRIVATE-TOKEN: ${TOKEN}" "${SERVER_URL}/api/v4/projects/${PROJECT_ID}/merge_requests"
}
# Pull the GitLab token from the environment here so we can work with them as
# arguments everywhere else. They're passed to us in the environment because
# *maybe* this is *slightly* safer than passing them in argv.
TOKEN="$UPDATE_PRODUCTION_PRIVATE_TOKEN"
# Before proceeding, remove the secrets from our environment so we don't pass
# them to child processes - none of which need them.
unset UPDATE_PRODUCTION_PRIVATE_TOKEN
main "$TOKEN" "$@"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment