Skip to content

Commit

Permalink
feat: create script / workflows for automatic PR creation (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch authored Jun 19, 2024
1 parent 76f5f6d commit 243e216
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
36 changes: 36 additions & 0 deletions .github/create-cli-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# © 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.
#

#!/bin/bash
set -ex

CLI_DIR=$(mktemp -d)
git clone --depth 1 https://github.com/snyk/cli $CLI_DIR
pushd $CLI_DIR
UPGRADE=$(go run scripts/upgrade-snyk-go-dependencies.go --name=snyk-ls)
LS_VERSION=$(echo $UPGRADE | sed 's/.*Sha: \(.*\) URL.*/\1/')
BRANCH=feat/automatic-upgrade-of-ls-to-$LS_VERSION
git checkout -b $BRANCH

git config --global user.email "team-ide-user@snyk.io"
git config --global user.name "Snyk Team IDE User"

git commit -am "feat: automatic integration of language server $LS_VERSION"
git push --set-upstream origin $BRANCH

COMMIT_HASH=$(git log --pretty=tformat:"%h" -n1 .)
gh pr create --repo github.com/snyk/cli --base main --fill-verbose --head $COMMIT_HASH --title "feat(language-server): integrate LS (automatic PR) ($LS_VERSION)" --body "$(echo $UPGRADE | sed 's/.*Message: \(.*\) URL.*$/\1/')"
popd
2 changes: 2 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

name: Build
on:
workflow_dispatch:
pull_request:

jobs:
Expand Down Expand Up @@ -248,3 +249,4 @@ jobs:
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }}
run: |
.github/upload-to-s3.sh --dryrun
28 changes: 28 additions & 0 deletions .github/workflows/create-cli-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Create CLI PR
on:
workflow_dispatch:

jobs:
create-pr:
runs-on: ubuntu-latest
steps:
- name: Prepare git
run: git config --global core.autocrlf false

- name: Checkout
uses: actions/checkout@v4

- 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 }}

- name: Create PR in CLI to integrate LS
env:
GH_TOKEN: ${{ HAMMERHEAD_GITHUB_PAT_SNYKLS }}
run: |
.github/create-cli-pr.sh
14 changes: 10 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: git config --global core.autocrlf false

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0 # does an unshallow checkout with tags & branches

Expand All @@ -42,7 +42,7 @@ jobs:
sed -En 's/^go[[:space:]]+([[:digit:].]+)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
make clean test
- name: Set up Git actions user
uses: fregante/setup-git-user@v1
uses: fregante/setup-git-user@v2

- name: Create Release Tag
run: |
Expand All @@ -126,7 +126,7 @@ jobs:
echo $LICENSES
- name: Build binaries and github release
uses: goreleaser/goreleaser-action@v3
uses: goreleaser/goreleaser-action@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_REGION: ${{ secrets.AWS_REGION }}
Expand All @@ -152,3 +152,9 @@ jobs:
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }}
run: |
.github/upload-to-s3.sh
- name: Create PR in CLI to integrate LS
env:
GH_TOKEN: ${{ HAMMERHEAD_GITHUB_PAT_SNYKLS }}
run: |
.github/create-cli-pr.sh

0 comments on commit 243e216

Please sign in to comment.