Skip to content

Commit

Permalink
Merge branch 'main' into update-plugins-2023/12/14/06/41/59
Browse files Browse the repository at this point in the history
  • Loading branch information
gounthar authored Dec 14, 2023
2 parents e9e798f + 27e0557 commit 9dd5fe0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
17 changes: 3 additions & 14 deletions .github/workflows/plugin_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,7 @@ jobs:
echo "No plugins need to be updated"
else
# Changes detected
echo "Plugins have been updated, creating a pull request"
# Create and checkout new branch
git checkout -b "$BRANCH_NAME"
# Add and commit changes
git add dockerfiles/plugins.txt
git commit -m "chore(jenkins): Update Jenkins plugins"
# Push changes to GitHub
git push -u origin "$BRANCH_NAME"
# Create pull request using gh command
gh pr create --title "chore(jenkins): Updates Jenkins plugins" --body "This pull request updates the Jenkins plugins listed in \`plugins.txt\`." --base "$BASE_BRANCH" --head "$BRANCH_NAME"
echo "Plugins have been updated, creating a pull request or modifying an existing one if it exists"
chmod +x ./.github/workflows/plugins-update-pr.sh
./.github/workflows/plugins-update-pr.sh
fi
45 changes: 45 additions & 0 deletions .github/workflows/plugins-update-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
# This script is used to update Jenkins plugins and create a pull request with the updates.
# It first checks if there is an existing pull request with the same title.
# If there is, it checks out the branch of the existing pull request.
# If there isn't, it creates and checks out a new branch.
# Then, it adds the updated plugins.txt file to the staging area and amends the latest commit with the changes.
# Finally, it pushes the changes to the 'origin' repository and creates a new pull request if there is no existing one.

# If changes are detected, a pull request is created or an existing one is modified.
echo "Plugins have been updated, creating a pull request or modifying an existing one if it exists"

# Set the default repository for the 'gh' command to 'gounthar/quickstart-tutorials'.
# gh repo set-default gounthar/quickstart-tutorials

# Define the title of the pull request.
PR_TITLE="chore(jenkins): Updates Jenkins plugins"

# Check if there is an existing pull request with the same title.
# If there is, get the branch name of the existing pull request.
# If there isn't, set EXISTING_PR_BRANCH to an empty string.
# shellcheck disable=SC1073
EXISTING_PR=$(gh pr list --search "$PR_TITLE" --json number,headRefName)
EXISTING_PR_BRANCH=$(echo "$EXISTING_PR" | jq -r 'if (type=="array" and length > 0) then .[0].data.repository.pullRequests.nodes[0].headRefName else "" end')

# If there is no existing pull request, create and checkout a new branch.
if [ -z "$EXISTING_PR_BRANCH" ]; then
git checkout -b "$BRANCH_NAME"
else
# If there is an existing pull request, checkout the existing branch.
git checkout "$EXISTING_PR_BRANCH"
fi

# Add the updated plugins.txt file to the staging area.
git add dockerfiles/plugins.txt

# Amend the latest commit with the changes in the staging area. The commit message is not changed.
git commit --amend --no-edit

# Push the changes to the 'origin' repository. The '-u' option sets the upstream branch to 'origin/HEAD'.
git push -u origin HEAD

# If there is no existing pull request, create a new one.
if [ -z "$EXISTING_PR_BRANCH" ]; then
gh pr create --title "$PR_TITLE" --body "This pull request updates the Jenkins plugins listed in \`plugins.txt\`." --base "$BASE_BRANCH" --head "$BRANCH_NAME"
fi

0 comments on commit 9dd5fe0

Please sign in to comment.