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: introduce automation for updating GAF in CLI #270

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
60 changes: 60 additions & 0 deletions .github/create-cli-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
#
# © 2024 Snyk Limited
#
# 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 -ex

CLI_DIR=$(mktemp -d)
PKG_NAME="go-application-framework"

gh repo clone [email protected]:snyk/cli.git $CLI_DIR
pushd "$CLI_DIR/cliv2"
LS_COMMIT_HASH=$(grep go-application-framework go.mod| cut -d "-" -f 4)
popd

WHAT_CHANGED=$(git whatchanged "$LS_COMMIT_HASH"...HEAD)
BODY=$(printf "## Changes since last integration of %s\n\n\`\`\`\n%s\n\`\`\`" "$PKG_NAME" "$WHAT_CHANGED")
BRANCH=feat/automatic-upgrade-of-$PKG_NAME

pushd $CLI_DIR
git checkout -B $BRANCH
git rebase --ignore-whitespace main

UPGRADE=$(go run scripts/upgrade-snyk-go-dependencies.go --name=$PKG_NAME)
PKG_VERSION=$(echo $UPGRADE | sed 's/.*Sha: \(.*\) URL.*/\1/')

git config --global user.email "[email protected]"
git config --global user.name "Snyk Team CLI"
git config --global gpg.format ssh
git config --global commit.gpgsign true

echo $PUB_SIGNING_KEY > signingkey.pub
git config --global user.signingkey ./signingkey.pub

git commit -am "chore(dependencies): automatic integration of $PKG_NAME $PKG_VERSION" || echo "No files to commit"

git push -f --set-upstream origin $BRANCH

TITLE="chore(dependencies): upgrade $PKG_NAME@$PKG_VERSION"
PR=$(gh pr list --search "$TITLE" 2>&1 | grep -e "$TITLE" | cut -f1)
if [[ ! $PR ]]; then
echo "Creating new PR"
gh pr create --repo github.com/snyk/cli --base main --head $BRANCH --title "$TITLE" --body "$BODY"
else
gh pr edit $PR --repo github.com/snyk/cli --body "$BODY"
fi
gh pr merge -m --auto --delete-branch
popd
37 changes: 37 additions & 0 deletions .github/workflows/create-cli-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Create CLI PR
on:
workflow_dispatch:
pull_request:
jobs:
create-pr:
runs-on: ubuntu-latest
steps:
- name: Prepare git
run: git config --global core.autocrlf false

- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Determine Go version
run: |
sed -En 's/^go[[:space:]]+([[:digit:].]+)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: "true"

- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.TEAM_IDE_USER_SSH }}

- name: Create PR in CLI to integrate LS
env:
GH_TOKEN: ${{ secrets.TEAM_CLI_GITHUB_PAT_GAF }}
GITHUB_TOKEN: ${{ secrets.TEAM_CLI_GITHUB_PAT_GAF }}
PUB_SIGNING_KEY: ${{ secrets.TEAM_CLI_USER_SSH_PUB }}
run: |
.github/create-cli-pr.sh
Loading