|
| 1 | +name: Create Dashboard Issue in signoz.io |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - "**/*.json" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + create-dashboard-issue: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v5 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Get changed dashboard JSON files |
| 22 | + id: changed-files |
| 23 | + run: | |
| 24 | + # Get the list of added JSON files in this PR |
| 25 | + ADDED_FILES=$(git diff --name-only --diff-filter=A origin/${{ github.base_ref }}...${{ github.sha }} | grep '\.json$' || true) |
| 26 | +
|
| 27 | + if [ -z "$ADDED_FILES" ]; then |
| 28 | + echo "No JSON files added" |
| 29 | + echo "added_files=" >> $GITHUB_OUTPUT |
| 30 | + echo "any_changed=false" >> $GITHUB_OUTPUT |
| 31 | + else |
| 32 | + echo "Added JSON files found:" |
| 33 | + echo "$ADDED_FILES" |
| 34 | +
|
| 35 | + # Convert to space-separated list for later use |
| 36 | + ADDED_FILES_SPACE=$(echo "$ADDED_FILES" | tr '\n' ' ' | sed 's/ $//') |
| 37 | + echo "added_files=$ADDED_FILES_SPACE" >> $GITHUB_OUTPUT |
| 38 | + echo "any_changed=true" >> $GITHUB_OUTPUT |
| 39 | + fi |
| 40 | +
|
| 41 | + - name: List added dashboard files |
| 42 | + if: steps.changed-files.outputs.any_changed == 'true' |
| 43 | + run: | |
| 44 | + echo "Added dashboard JSON files:" |
| 45 | + echo "${{ steps.changed-files.outputs.added_files }}" |
| 46 | +
|
| 47 | + - name: Validate configuration |
| 48 | + if: steps.changed-files.outputs.any_changed == 'true' |
| 49 | + run: | |
| 50 | + if [ -z "${{ vars.TARGET_REPO_OWNER }}" ] || [ -z "${{ vars.TARGET_REPO_NAME }}" ]; then |
| 51 | + echo "❌ Error: TARGET_REPO_OWNER and TARGET_REPO_NAME variables must be set" |
| 52 | + echo "Please configure these in your repository settings:" |
| 53 | + echo "Settings → Secrets and variables → Actions → Variables" |
| 54 | + echo "" |
| 55 | + echo "Required variables:" |
| 56 | + echo "- TARGET_REPO_OWNER: SigNoz" |
| 57 | + echo "- TARGET_REPO_NAME: signoz.io" |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | +
|
| 61 | + if [ -z "${{ secrets.CROSS_REPO_TOKEN }}" ]; then |
| 62 | + echo "❌ Error: CROSS_REPO_TOKEN secret must be set" |
| 63 | + echo "Please create a Personal Access Token and add it as a secret:" |
| 64 | + echo "Settings → Secrets and variables → Actions → Secrets" |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | +
|
| 68 | + if [ -z "${{ vars.ISSUE_ASSIGNEE }}" ]; then |
| 69 | + echo "❌ Error: ISSUE_ASSIGNEE variable must be set" |
| 70 | + echo "Please configure this in your repository settings:" |
| 71 | + echo "Settings → Secrets and variables → Actions → Variables" |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | +
|
| 75 | + echo "✅ Configuration validated" |
| 76 | + echo "Target repository: ${{ vars.TARGET_REPO_OWNER }}/${{ vars.TARGET_REPO_NAME }}" |
| 77 | +
|
| 78 | + - name: Find existing issue in signoz.io |
| 79 | + id: find-issue |
| 80 | + if: steps.changed-files.outputs.any_changed == 'true' |
| 81 | + run: | |
| 82 | + # Search for existing issue in signoz.io |
| 83 | + ISSUE_NUMBER=$(gh issue list \ |
| 84 | + --repo ${{ vars.TARGET_REPO_OWNER }}/${{ vars.TARGET_REPO_NAME }} \ |
| 85 | + --search "Dashboard Changes in PR #${{ github.event.pull_request.number }} in:title" \ |
| 86 | + --json number \ |
| 87 | + --jq '.[0].number // empty') |
| 88 | +
|
| 89 | + echo "existing-issue=$ISSUE_NUMBER" >> $GITHUB_OUTPUT |
| 90 | +
|
| 91 | + if [ -n "$ISSUE_NUMBER" ]; then |
| 92 | + echo "Found existing issue #$ISSUE_NUMBER in signoz.io" |
| 93 | + else |
| 94 | + echo "No existing issue found in signoz.io" |
| 95 | + fi |
| 96 | + env: |
| 97 | + GITHUB_TOKEN: ${{ secrets.CROSS_REPO_TOKEN }} |
| 98 | + |
| 99 | + - name: Generate issue content |
| 100 | + id: issue-content |
| 101 | + if: steps.changed-files.outputs.any_changed == 'true' |
| 102 | + run: | |
| 103 | + # Create issue body |
| 104 | + { |
| 105 | + echo "# 📊 New Dashboard Changes" |
| 106 | + echo "" |
| 107 | + echo "**Source Repository:** ${{ github.repository }}" |
| 108 | + echo "**Pull Request:** [#${{ github.event.pull_request.number }}](${{ github.event.pull_request.html_url }})" |
| 109 | + echo "**Branch:** \`${{ github.head_ref }}\`" |
| 110 | + echo "**Author:** @${{ github.event.pull_request.user.login }}" |
| 111 | + echo "" |
| 112 | + echo "## Dashboard JSON Files Added:" |
| 113 | + echo "" |
| 114 | + |
| 115 | + # Process each added file |
| 116 | + for file in ${{ steps.changed-files.outputs.added_files }}; do |
| 117 | + file_url="https://github.com/${{ github.repository }}/blob/${{ github.event.pull_request.head.sha }}/${file}" |
| 118 | + echo "- [\`${file}\`](${file_url})" |
| 119 | + done |
| 120 | + |
| 121 | + echo "" |
| 122 | + echo "## Next Steps" |
| 123 | + echo "" |
| 124 | + echo "- [ ] Review dashboard configuration" |
| 125 | + echo "- [ ] Test dashboard functionality" |
| 126 | + echo "- [ ] Update documentation if needed" |
| 127 | + echo "" |
| 128 | + echo "---" |
| 129 | + echo "*This issue was automatically created by the [Dashboard workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})*" |
| 130 | + } > issue_content.md |
| 131 | +
|
| 132 | + cat issue_content.md |
| 133 | +
|
| 134 | + - name: Create or update issue in signoz.io |
| 135 | + if: steps.changed-files.outputs.any_changed == 'true' |
| 136 | + uses: actions/github-script@v8 |
| 137 | + with: |
| 138 | + github-token: ${{ secrets.CROSS_REPO_TOKEN }} |
| 139 | + script: | |
| 140 | + const fs = require('fs'); |
| 141 | + const issueBody = fs.readFileSync('issue_content.md', 'utf8'); |
| 142 | + const existingIssue = '${{ steps.find-issue.outputs.existing-issue }}'; |
| 143 | + const targetOwner = '${{ vars.TARGET_REPO_OWNER }}'; |
| 144 | + const targetRepo = '${{ vars.TARGET_REPO_NAME }}'; |
| 145 | +
|
| 146 | + if (existingIssue) { |
| 147 | + // Update existing issue |
| 148 | + await github.rest.issues.update({ |
| 149 | + owner: targetOwner, |
| 150 | + repo: targetRepo, |
| 151 | + issue_number: parseInt(existingIssue), |
| 152 | + body: issueBody |
| 153 | + }); |
| 154 | + console.log(`Updated issue #${existingIssue} in ${targetOwner}/${targetRepo}`); |
| 155 | + } else { |
| 156 | + // Create new issue |
| 157 | + const issue = await github.rest.issues.create({ |
| 158 | + owner: targetOwner, |
| 159 | + repo: targetRepo, |
| 160 | + title: `Dashboard Changes in PR #${{ github.event.pull_request.number }} from ${{ github.repository }}`, |
| 161 | + body: issueBody, |
| 162 | + labels: ['dashboard', 'automated-issue'], |
| 163 | + assignees: ['${{ vars.ISSUE_ASSIGNEE }}'] |
| 164 | + }); |
| 165 | + console.log(`Created issue #${issue.data.number} in ${targetOwner}/${targetRepo}`); |
| 166 | + } |
| 167 | +
|
| 168 | + - name: Delete previous bot comments |
| 169 | + if: steps.changed-files.outputs.any_changed == 'true' |
| 170 | + uses: actions/github-script@v8 |
| 171 | + with: |
| 172 | + script: | |
| 173 | + const comments = await github.rest.issues.listComments({ |
| 174 | + owner: context.repo.owner, |
| 175 | + repo: context.repo.repo, |
| 176 | + issue_number: context.issue.number |
| 177 | + }); |
| 178 | +
|
| 179 | + for (const comment of comments.data) { |
| 180 | + if (comment.user.type === 'Bot' && comment.body.includes('Dashboard files added in this PR')) { |
| 181 | + await github.rest.issues.deleteComment({ |
| 182 | + owner: context.repo.owner, |
| 183 | + repo: context.repo.repo, |
| 184 | + comment_id: comment.id |
| 185 | + }); |
| 186 | + } |
| 187 | + } |
| 188 | +
|
| 189 | + - name: Comment on PR |
| 190 | + if: steps.changed-files.outputs.any_changed == 'true' |
| 191 | + uses: actions/github-script@v8 |
| 192 | + with: |
| 193 | + script: | |
| 194 | + const files = '${{ steps.changed-files.outputs.added_files }}'.split(' '); |
| 195 | +
|
| 196 | + let comment = `## 📊 Dashboard files added in this PR\n\n`; |
| 197 | +
|
| 198 | + for (const file of files) { |
| 199 | + const fileUrl = `https://github.com/${{ github.repository }}/blob/${{ github.event.pull_request.head.sha }}/${file}`; |
| 200 | + comment += `- [\`${file}\`](${fileUrl})\n`; |
| 201 | + } |
| 202 | +
|
| 203 | + comment += `\n✅ An issue has been created in [\`SigNoz/signoz.io\`](https://github.com/SigNoz/signoz.io/issues) to track these dashboard changes.`; |
| 204 | +
|
| 205 | + await github.rest.issues.createComment({ |
| 206 | + owner: context.repo.owner, |
| 207 | + repo: context.repo.repo, |
| 208 | + issue_number: context.issue.number, |
| 209 | + body: comment |
| 210 | + }); |
0 commit comments