diff --git a/.github/create-cli-pr.sh b/.github/create-cli-pr.sh new file mode 100644 index 000000000..ab7577e32 --- /dev/null +++ b/.github/create-cli-pr.sh @@ -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 git@github.com: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 "team-cli@snyk.io" + 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 \ No newline at end of file diff --git a/.github/workflows/create-cli-pr.yml b/.github/workflows/create-cli-pr.yml new file mode 100644 index 000000000..b0d882e37 --- /dev/null +++ b/.github/workflows/create-cli-pr.yml @@ -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/ssh-agent@v0.9.0 + 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 \ No newline at end of file