-
Notifications
You must be signed in to change notification settings - Fork 201
76 lines (59 loc) · 3.01 KB
/
plugin_update.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: Plugins Update file test
on:
push:
branches:
- main
workflow_dispatch:
schedule:
- cron: '0 8 * * *' # run daily at eight
jobs:
check-plugins:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure git & gh
run: |
echo ${{ secrets.GH_TOKEN }} | gh auth login --with-token
gh auth status
git config --global user.email "gounthar@gmail.com"
git config --global user.name "gounthar"
- name: Set branch Names and start the containers
run: |
# Set the name of the branch to create the pull request from
echo "BRANCH_NAME=update-plugins-$(date +'%Y/%m/%d/%H/%M/%S')" >> $GITHUB_ENV
# Set the name of the branch to create the pull request to
echo "BASE_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
# Start the docker containers
tree .
docker compose -f ./docker-compose.yaml --profile default up -d --force-recreate
- name: print GITHUB_ENV file
run: cat $GITHUB_ENV
- name: Waiting for service to be ready
run: |
# Check If Jenkins is running or not
# If the message is found, awk exits with a non-zero status (1), and the loop continues.
# If the message is not found, the loop exits, and the "Jenkins is running" message is displayed.
timeout 60 bash -c 'until curl -s -f http://127.0.0.1:8080/login > /dev/null; do sleep 5; done' && echo "Jenkins is running" || echo "Jenkins is not running"
echo "Jenkins is ready"
JENKINS_VERSION=$(curl -s -I -k http://admin:admin@127.0.0.1:8080 | grep -i '^X-Jenkins:' | awk '{print $2}')
echo "Jenkins version is: $JENKINS_VERSION"
# Uses jenkins-plugin-cli to update the plugin.txt and update it
docker ps | grep controller | awk '{print $1}' | xargs -I {} docker exec {} jenkins-plugin-cli --plugin-file /usr/share/jenkins/ref/plugins.txt --no-download --available-updates --output txt > dockerfiles/plugins.txt
# Check if the plugins.txt file has been modified
if git diff --quiet -- dockerfiles/plugins.txt; then
# No changes
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"
fi