Skip to content

Commit 9c94b51

Browse files
committed
feat: migrate github action definition from docker to node.js
This update replaces the Docker-based GitHub Action with a Node.js-based implementation for better maintainability and compatibility with our existing JavaScript tooling. It also fixes an issue with the permissions of the output files from the previous Docker implementation. - Added pre-commit and commit message linting hooks using Husky. - Integrated ESLint for code linting. - Migrated the previous shell script to an ES6 script. - Action definition switched from `using: docker` to `using: node20`. - Designed the script to be dependency-free, eliminating the need for compilation or distributing a `dist` folder.
1 parent 3a54450 commit 9c94b51

20 files changed

+8449
-164
lines changed

.commitlintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": [
3+
"@commitlint/config-conventional"
4+
]
5+
}

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ indent_size = 2
88
insert_final_newline = true
99
trim_trailing_whitespace = true
1010

11+
[*.mjs]
12+
quote_type = single
13+
1114
[*.md]
1215
max_line_length = 100

.githooks/commit-msg

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/quality.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ jobs:
1212
- name: Checkout code
1313
uses: actions/checkout@v4
1414

15-
- name: Set up Docker Buildx
16-
uses: docker/setup-buildx-action@v3
15+
- name: Set up Node.js
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: '22'
1719

18-
- name: Build Docker image
19-
run: docker build -t grafana-sync-action .
20+
- name: Install dependencies
21+
run: |
22+
npm pkg delete scripts.prepare
23+
npm ci
24+
25+
- name: Run JS and linter
26+
run: |
27+
npm run eslint

.github/workflows/release.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,13 @@ jobs:
2424
with:
2525
node-version: '22'
2626

27-
- name: Install semantic-release
27+
- name: Install dependencies
2828
run: |
29-
npm install -g @semantic-release/[email protected] \
30-
@semantic-release/[email protected] \
31-
@semantic-release/[email protected] \
32-
33-
29+
npm pkg delete scripts.prepare
30+
npm ci
3431
3532
- name: Release
3633
id: semantic-release
3734
env:
3835
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39-
run: |
40-
npx semantic-release
36+
run: npx semantic-release

.gitignore

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,56 @@
1-
### Intellij ###
2-
.idea/
3-
*.iml
4-
*.iws
5-
modules.xml
6-
*.ipr
7-
cmake-build-*/
8-
out/
9-
.idea_modules/
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Compiled binary addons (https://nodejs.org/api/addons.html)
20+
build/Release
21+
22+
# Dependency directories
23+
node_modules/
24+
jspm_packages/
25+
26+
# Optional npm cache directory
27+
.npm
28+
29+
# Optional eslint cache
30+
.eslintcache
31+
32+
# Optional stylelint cache
33+
.stylelintcache
34+
35+
# Parcel cache
36+
.parcel-cache
37+
38+
# Output of 'npm pack'
39+
*.tgz
40+
41+
# dotenv environment variable files
42+
.env
43+
.env.development.local
44+
.env.test.local
45+
.env.production.local
46+
.env.local
47+
48+
# Generated output
49+
dist
50+
coverage
51+
52+
# Intellij
53+
.idea
1054

1155
# VisualStudioCode
1256
.vscode-test

.husky/commit-msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx --no -- commitlint --edit ${1}

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm run eslint

Dockerfile

Lines changed: 0 additions & 8 deletions
This file was deleted.

README.md

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,74 +19,80 @@ A GitHub Action that automates the process of backing up Grafana dashboards.
1919

2020
- `GRAFANA_URL`: The URL of your Grafana instance.
2121
- `GRAFANA_API_KEY`: The API key for Grafana authentication.
22-
- _(Optional)_ `GH_PAT`: A GitHub Personal Access Token with `repo` permissions, needed only if
23-
automating PR creation.
2422

2523
3. **Create a workflow file** in `.github/workflows/grafana-backup.yml` with the following content:
2624

2725
```yaml
2826
name: Grafana Dashboard Backup
2927

3028
on:
31-
schedule:
32-
- cron: '0 2 * * *' # Runs every day at 2 AM UTC
33-
workflow_dispatch: # Allows manual triggering
29+
schedule:
30+
- cron: '0 2 * * *'
31+
workflow_dispatch:
3432

3533
jobs:
36-
backup:
37-
runs-on: ubuntu-latest
38-
39-
steps:
40-
- name: Checkout repository
41-
uses: actions/checkout@v4
42-
43-
- name: Run Grafana Sync
44-
uses: srgssr/grafana-sync-action@v1
45-
with:
46-
grafana-url: ${{ secrets.GRAFANA_URL }}
47-
api-key: ${{ secrets.GRAFANA_API_KEY }}
48-
output-dir: dashboards
49-
50-
- name: Commit and Push Changes
51-
run: |
52-
git config --global user.name "github-actions[bot]"
53-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
54-
git add dashboards
55-
git commit -m "Automated backup of Grafana dashboards" || echo "No changes to commit"
56-
git push
57-
58-
# (Optional) Create a Pull request using peter-evans/create-pull-request
59-
- name: Create Pull Request
60-
uses: peter-evans/create-pull-request@v7
61-
with:
62-
token: ${{ secrets.GH_PAT }}
63-
commit-message: "chore: automated Grafana dashboard backup"
64-
title: "chore: automated backup of Grafana dashboards"
65-
body: "This PR contains the latest Grafana dashboard updates."
66-
branch: "backup/grafana-dashboards"
67-
delete-branch: true
34+
backup:
35+
runs-on: ubuntu-latest
36+
37+
permissions:
38+
contents: write
39+
pull-requests: write
40+
41+
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@v4
44+
with:
45+
fetch-depth: 0
46+
47+
- name: Run Grafana Sync
48+
uses: srgssr/[email protected]
49+
with:
50+
grafana-url: ${{ secrets.GRAFANA_URL }}
51+
api-key: ${{ secrets.GRAFANA_API_KEY }}
52+
dir: 'dashboards'
53+
54+
- name: Create Pull Request
55+
uses: peter-evans/create-pull-request@v7
56+
with:
57+
token: ${{ secrets.GITHUB_TOKEN }}
58+
add-paths: dashboards
59+
commit-message: "chore: automated grafana dashboard backup"
60+
committer: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
61+
author: "${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>"
62+
signoff: false
63+
draft: false
64+
delete-branch: true
65+
branch: "chore/update-grafana-dashboards"
66+
title: "chore: automated backup of grafana dashboards"
67+
body: "This pull request contains the latest backup of our Grafana dashboards"
6868
```
6969
7070
**Running the Action**
7171
72-
- The action will **automatically run daily at 2 AM UTC** to check for changes.
72+
- The action will **automatically run daily at 2 AM** to check for changes.
7373
- You can also **manually trigger** the workflow from the GitHub Actions tab.
7474
- If changes are detected, it will create a **pull request** containing the updated dashboards.
7575
7676
## Contributing
7777
7878
Contributions are welcome! If you'd like to contribute, please follow the project's code style and
79-
linting rules.
79+
linting rules. Here are some commands to help you get started:
80+
81+
Check your JavaScript code:
82+
83+
```shell
84+
npm run eslint
85+
```
8086

8187
All commits must follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
8288
format to ensure compatibility with our automated release system. A pre-commit hook is available to
8389
validate commit messages.
8490

85-
You can set up hook to automate these checks before commiting and pushing your changes, to do so
86-
update the Git hooks path:
91+
You can set up hook to automate these checks before commiting and pushing your changes. Enable this
92+
hook by running the `prepare` script:
8793

88-
```bash
89-
git config core.hooksPath .githooks/
94+
```shell
95+
npm run prepare
9096
```
9197

9298
Refer to our [Contribution Guide](docs/CONTRIBUTING.md) for more detailed information.

0 commit comments

Comments
 (0)