Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukochka committed Jun 27, 2024
1 parent fe89ac7 commit d9ef433
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 80 deletions.
73 changes: 73 additions & 0 deletions .github/actions/merge-changes/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Merge Changes
description: Open PR with changes and merge it if all tests are passed
inputs:
target-branch:
description: Target branch for the changes to be merged into
required: true
default: ${{ github.event.repository.default_branch }}
current-branch:
description: Current branch
required: false
default: automatic-plugin-examples-update
commit-message:
description: Commit message
required: true
default: Commit changes from CI
app-id:
description: GitHub App ID
required: true
app-pem:
description: GitHub App PEM
required: true
runs:
using: "composite"
steps:
- name: Set up Git configuration
shell: bash
run: |
git config user.name 'grafana-delivery-bot[bot]'
git config user.email '132647405+grafana-delivery-bot[bot]@users.noreply.github.com'
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: "${{ inputs.app-id }}"
private_key: "${{ inputs.app-pem }}"

- name: Create a branch
shell: bash
run: git checkout --progress -B ${{ inputs.current-branch }}

# - name: Commit changes
# shell: bash
# run: |
# git add --all -- .
# git commit -m "${{ inputs.commit-message }}"
# git show --stat

# - name: Push changes
# shell: bash
# run: git push origin ${{ inputs.current-branch }} --force-with-lease

- name: Create PR
uses: peter-evans/create-pull-request@v6
with:
token: ${{ steps.generate_token.outputs.token }}
branch: new-update-plugin-examples
delete-branch: true
commit-message: 'chore: update configuration to latest version'
title: 'Chore: Bump plugin-examples configuration to latest version'
body: |
Bumps [`grafana-plugin-examples`](https://github.com/grafana/grafana-plugin-examples) configuration to the latest version.
**Notes for reviewer:**
This is an auto-generated PR which ran `npx -y @grafana/create-plugin@latest update`, updates plugin.json files and docker-compose files for each plugin example
Please review the changes thoroughly before merging.
# - name: Clean up
# if: ${{ cancelled() }}
# shell: bash
# run: |
# git checkout ${{ inputs.target-branch }}
# git branch -D ${{ inputs.current-branch }}
74 changes: 15 additions & 59 deletions .github/workflows/automatic-update.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,30 @@
name: Update Grafana Version

on:
schedule:
- cron: '0 0 1 * *' # Runs at 00:00 on the first day of every month
workflow_dispatch: # Allows you to manually trigger the workflow
on: push
# schedule:
# - cron: '0 0 1 * *' # Runs at 00:00 on the first day of every month
# workflow_dispatch: # Allows you to manually trigger the workflow

jobs:
update-grafana:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Git configuration
run: |
git config user.name 'github-actions'
git config user.email '[email protected]'
- name: Set up permissions
run: chmod +x scripts/update-grafana-version.sh
uses: actions/checkout@v4

- name: Update Grafana version
run: scripts/update-grafana-version.sh

- name: Commit changes
run: |
git add .
git commit -m "Update Grafana version"
continue-on-error: true
bash scripts/update-grafana-version.sh
git status
- name: Push changes
- name: Check the status of the repo
id: status
run: |
git push origin update-grafana-version
continue-on-error: true

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: update-grafana-version
title: Update Grafana version
body: Automatic update of Grafana version.
labels: automatic update
assignees: ${{ github.actor }}

test-and-merge:
needs: update-grafana
runs-on: ubuntu-latest
if: github.event.pull_request.merged == false

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Run tests
run: ./scripts/run-tests.sh # Adjust this command to your test script
echo "status=$(git diff-index --quiet --exit-code HEAD && echo '0' || echo '1')" >> $GITHUB_OUTPUT
- name: Merge Pull Request
if: success()
uses: actions/github-script@v3
- name: Apply changes
if: ${{ steps.status.outputs.status == '1' }}
uses: ./.github/actions/merge-changes
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pullRequest = context.payload.pull_request;
if (pullRequest) {
await github.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullRequest.number,
merge_method: 'merge'
});
}
app-id: ${{ secrets.APP_ID }}
app-pem: ${{ secrets.APP_PEM }}
2 changes: 1 addition & 1 deletion examples/datasource-http-backend/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
context: ./.config
args:
grafana_image: ${GRAFANA_IMAGE:-grafana-enterprise}
grafana_version: ${GRAFANA_VERSION:-10.4.0}
grafana_version: ${GRAFANA_VERSION:-10.1.0}
ports:
- 3000:3000/tcp
volumes:
Expand Down
40 changes: 20 additions & 20 deletions scripts/update-grafana-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
#
GRAFANA_VERSION_TARGET=${1:-10.3.3}

dirs=$(find examples -type f -name 'package.json' -not -path '*/node_modules/*' -exec dirname {} \;)
#dirs=('examples/panel-plotly' 'examples/panel-scatterplot' 'examples/panel-visx')
for plugin in $dirs; do
if [ -d "$plugin" ]; then # Check if it is indeed a directory
echo "Processing plugin folder: $plugin"
# Run the npx command in the plugin directory
(cd "$plugin" && npx @grafana/create-plugin@latest update --force && npm install && rm -rf node_modules)
fi
done
# dirs=$(find examples -type f -name 'package.json' -not -path '*/node_modules/*' -exec dirname {} \;)
# #dirs=('examples/panel-plotly' 'examples/panel-scatterplot' 'examples/panel-visx')
# for plugin in $dirs; do
# if [ -d "$plugin" ]; then # Check if it is indeed a directory
# echo "Processing plugin folder: $plugin"
# # Run the npx command in the plugin directory
# (cd "$plugin" && npx @grafana/create-plugin@latest update --force && npm install && rm -rf node_modules)
# fi
# done

###############################################
# Upgrade plugin.json files
###############################################
get_newer_version () { printf "%s\n" "$@" | sort --version-sort | tail -1 ; }

plugin_files=$(find examples -type f -name 'plugin.json' -not -path '*/node_modules/*')
# Iterate over each plugin.json file
for file in $plugin_files; do
# Get the current value of dependencies.grafanaDependency using jq
current_dependency=$(jq -r '.dependencies.grafanaDependency' "$file")
target_version=$(get_newer_version "$(echo $current_dependency | sed -n 's|[=<>~!]*\([0-9]*.[0-9]*.[0-9]*\)|\1|p')" "$GRAFANA_VERSION_TARGET")
# Modify the property to >$GRAFANA_VERSION_TARGET using jq and update the file
modified_dependency=$(echo "$current_dependency" | jq -n --arg target ">=$target_version" '$target')
jq --argjson modified "$modified_dependency" '.dependencies.grafanaDependency = $modified' "$file" >"$file.tmp" && mv "$file.tmp" "$file"
done
# plugin_files=$(find examples -type f -name 'plugin.json' -not -path '*/node_modules/*')
# # Iterate over each plugin.json file
# for file in $plugin_files; do
# # Get the current value of dependencies.grafanaDependency using jq
# current_dependency=$(jq -r '.dependencies.grafanaDependency' "$file")
# target_version=$(get_newer_version "$(echo $current_dependency | sed -n 's|[=<>~!]*\([0-9]*.[0-9]*.[0-9]*\)|\1|p')" "$GRAFANA_VERSION_TARGET")
# # Modify the property to >$GRAFANA_VERSION_TARGET using jq and update the file
# modified_dependency=$(echo "$current_dependency" | jq -n --arg target ">=$target_version" '$target')
# jq --argjson modified "$modified_dependency" '.dependencies.grafanaDependency = $modified' "$file" >"$file.tmp" && mv "$file.tmp" "$file"
# done

###############################################
# Upgrade docker-compose files
Expand Down Expand Up @@ -57,4 +57,4 @@ done
# Upgrade grafana-plugin-sdk-go to latest version
###############################################

./scripts/update-backend-sdk.sh
#./scripts/update-backend-sdk.sh

0 comments on commit d9ef433

Please sign in to comment.