Skip to content

Commit 80c981e

Browse files
Merge pull request #118 from YashasviDevtron/pr-sync-github-action
chore: adding gh-action script to create pr for multi-repo dependency sync
2 parents 8ee178f + 6ecac6b commit 80c981e

File tree

3 files changed

+239
-0
lines changed

3 files changed

+239
-0
lines changed

.github/config/multi-gitter-config

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# The username of the assignees to be added on the pull request.
2+
assignees:
3+
- systemsdt
4+
5+
# Email of the committer. If not set, the global git config setting will be used.
6+
author-email:
7+
8+
# Name of the committer. If not set, the global git config setting will be used.
9+
author-name:
10+
11+
# The branch which the changes will be based on.
12+
base-branch:
13+
14+
# Base URL of the target platform, needs to be changed for GitHub enterprise, a self-hosted GitLab instance, Gitea or BitBucket.
15+
base-url:
16+
17+
# The name of the branch where changes are committed.
18+
branch:
19+
20+
# The temporary directory where the repositories will be cloned. If not set, the default os temporary directory will be used.
21+
clone-dir:
22+
23+
# Use a code search to find a set of repositories to target (GitHub only). Repeated results from a given repository will be ignored, forks are NOT included by default (use `fork:true` to include them). See the GitHub documentation for full syntax: https://docs.github.com/en/search-github/searching-on-github/searching-code.
24+
code-search:
25+
26+
# The commit message. Will default to title + body if none is set.
27+
commit-message:
28+
29+
# The maximum number of concurrent runs.
30+
concurrent: 1
31+
32+
# What should happen if the branch already exist.
33+
# Available values:
34+
# skip: Skip making any changes to the existing branch and do not create a new pull request.
35+
# replace: Replace the existing content of the branch by force pushing any new changes, then reuse any existing pull request, or create a new one if none exist.
36+
conflict-strategy: skip
37+
38+
# Create pull request(s) as draft.
39+
draft: false
40+
41+
# Run without pushing changes or creating pull requests.
42+
dry-run: false
43+
44+
# Limit fetching to the specified number of commits. Set to 0 for no limit.
45+
fetch-depth: 1
46+
47+
# Fork the repository instead of creating a new branch on the same owner.
48+
fork: false
49+
50+
# If set, make the fork to the defined value. Default behavior is for the fork to be on the logged in user.
51+
fork-owner:
52+
53+
# The type of git implementation to use.
54+
# Available values:
55+
# go: Uses go-git, a Go native implementation of git. This is compiled with the multi-gitter binary, and no extra dependencies are needed.
56+
# cmd: Calls out to the git command. This requires git to be installed and available with by calling "git".
57+
git-type: cmd
58+
59+
# Labels to be added to any created pull request.
60+
labels:
61+
- dependencies
62+
- multi-gitter
63+
64+
# The file where all logs should be printed to. "-" means stdout.
65+
log-file: "-"
66+
67+
# The formatting of the logs. Available values: text, json, json-pretty.
68+
log-format: text
69+
70+
# The level of logging that should be made. Available values: trace, debug, info, error.
71+
log-level: info
72+
73+
# If this value is set, reviewers will be randomized.
74+
max-reviewers: 0
75+
76+
# If this value is set, team reviewers will be randomized
77+
max-team-reviewers: 0
78+
79+
# The name of a GitHub organization. All repositories in that organization will be used.
80+
# org:
81+
# - devtron-labs
82+
83+
# The file that the output of the script should be outputted to. "-" means stdout.
84+
output: "-"
85+
86+
# Don't use any terminal formatting when printing the output.
87+
plain-output: false
88+
89+
# The platform that is used. Available values: github, gitlab, gitea, bitbucket_server, bitbucket_cloud. Note: bitbucket_cloud is in Beta
90+
platform: github
91+
92+
# The body of the commit message. Will default to everything but the first line of the commit message if none is set.
93+
pr-body: "This PR was created by multi-gitter to sync common-lib changes across multiple repositories."
94+
95+
# The title of the PR. Will default to the first line of the commit message if none is set.
96+
pr-title:
97+
98+
# The name, including owner of a GitLab project in the format "ownerName/repoName".
99+
project:
100+
- group/project
101+
102+
# Skip pull request and only push the feature branch.
103+
push-only: false
104+
105+
# The name, including owner of a GitHub repository in the format "ownerName/repoName".
106+
repo:
107+
- devtron-labs/common-lib-private
108+
- devtron-labs/devtron-enterprise
109+
- devtron-labs/kubewatch
110+
- devtron-labs/kubelink-enterprise
111+
- devtron-labs/image-scanner-enterprise
112+
- devtron-labs/lens
113+
- devtron-labs/ci-runner-enterprise
114+
- devtron-labs/git-sensor-enterprise
115+
- chart-sync-enterprise
116+
- devtron-labs/devtron
117+
- devtron-labs/kubelink
118+
- devtron-labs/image-scanner
119+
- devtron-labs/ci-runner
120+
- devtron-labs/git-sensor
121+
- chart-sync
122+
123+
124+
125+
# Exclude repositories that match with a given Regular Expression
126+
repo-exclude:
127+
128+
# Include repositories that match with a given Regular Expression
129+
repo-include:
130+
131+
# Use a repository search to find repositories to target (GitHub only). Forks are NOT included by default, use `fork:true` to include them. See the GitHub documentation for full syntax: https://docs.github.com/en/search-github/searching-on-github/searching-for-repositories.
132+
repo-search:
133+
134+
# The username of the reviewers to be added on the pull request.
135+
reviewers:
136+
- prkhrkat
137+
138+
139+
140+
141+
# Skip repositories which are forks.
142+
skip-forks: false
143+
144+
# Skip pull request and directly push to the branch.
145+
skip-pr: false
146+
147+
# Skip changes on specified repositories, the name is including the owner of repository in the format "ownerName/repoName".
148+
skip-repo:
149+
- example
150+
151+
# Use SSH cloning URL instead of HTTPS + token. This requires that a setup with ssh keys that have access to all repos and that the server is already in known_hosts.
152+
ssh-auth: false
153+
154+
# The personal access token for the targeting platform. Can also be set using the GITHUB_TOKEN/GITLAB_TOKEN/GITEA_TOKEN/BITBUCKET_SERVER_TOKEN/BITBUCKET_CLOUD_APP_PASSWORD environment variable.
155+
token:
156+

.github/scripts/update-version.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# Title: Updates a go module to a new (patch/minor) version
4+
5+
### Change these values ###
6+
MODULE=github.com/devtron-labs/common-lib
7+
VERSION=${VERSION}
8+
9+
echo "Commit SHA: ${VERSION}"
10+
11+
# Stop the script if any command fails
12+
set -e
13+
14+
# Check if the module already exists, abort if it does not
15+
go list -m $MODULE &> /dev/null
16+
status_code=$?
17+
if [ $status_code -ne 0 ]; then
18+
echo "Module \"$MODULE\" does not exist"
19+
exit 1
20+
fi
21+
22+
# Update the module to the specified version
23+
go get $MODULE@$VERSION
24+
25+
go mod tidy
26+
27+
# Vendor the dependencies
28+
go mod vendor
29+
30+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Creating PR using Multi-Gitter
2+
3+
on:
4+
pull_request:
5+
types: [opened]
6+
branches:
7+
- develop
8+
- main
9+
10+
jobs:
11+
update-dependencies:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v2
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: '>=1.17.0'
21+
22+
- name: Install multi-gitter
23+
run: curl -s https://raw.githubusercontent.com/lindell/multi-gitter/b62a2dfda0ed266502f7c71f7ce79f8fd9c26bf6/install.sh | sh
24+
25+
- name: Get PR details
26+
env:
27+
HEAD_BRANCH: ${{ github.event.pull_request.head.ref }}
28+
BASE_BRANCH: ${{ github.event.pull_request.base.ref }}
29+
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
30+
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
31+
PR_AUTHOR_ID: ${{ github.event.pull_request.user.id }}
32+
run: |
33+
echo "HEAD_BRANCH=$HEAD_BRANCH" >> $GITHUB_ENV
34+
echo "BASE_BRANCH=$BASE_BRANCH" >> $GITHUB_ENV
35+
echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_ENV
36+
echo "PR_AUTHOR=$PR_AUTHOR" >> $GITHUB_ENV
37+
echo "PR_AUTHOR_ID=$PR_AUTHOR_ID" >> $GITHUB_ENV
38+
echo "PR_AUTHOR_EMAIL=${PR_AUTHOR_ID}+${PR_AUTHOR}@users.noreply.github.com" >> $GITHUB_ENV
39+
40+
- name: Update script with PR details
41+
run: |
42+
sed -i 's/VERSION=.*/VERSION=${{ env.COMMIT_SHA }}/' .github/config/multi-gitter-config
43+
sed -i 's/PR_AUTHOR=.*/PR_AUTHOR=${{ env.PR_AUTHOR }}/' .github/config/multi-gitter-config
44+
sed -i 's/HEAD_BRANCH=.*/HEAD_BRANCH=${{ env.HEAD_BRANCH }}/' .github/config/multi-gitter-config
45+
sed -i 's/HEAD_BRANCH=.*/HEAD_BRANCH=${{ env.HEAD_BRANCH }}/' .github/scripts/update-version.sh
46+
sed -i 's/BASE_BRANCH=.*/BASE_BRANCH=${{ env.BASE_BRANCH }}/' .github/scripts/update-version.sh
47+
48+
- name: Run multi-gitter
49+
env:
50+
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
51+
run: |
52+
chmod +x .github/scripts/update-version.sh
53+
multi-gitter run .github/scripts/update-version.sh --token "$GITEA_TOKEN" --base-branch "$BASE_BRANCH" --branch "$HEAD_BRANCH" --author-name "$PR_AUTHOR" --author-email "$PR_AUTHOR_EMAIL" --pr-title "fix: sync with changes from $HEAD_BRANCH of common-lib" --config .github/config/multi-gitter-config

0 commit comments

Comments
 (0)