|
| 1 | +# Copyright 2025- FlagOS Contributors |
| 2 | +# |
| 3 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | +# of this software and associated documentation files (the "Software"), to deal |
| 5 | +# in the Software without restriction, including without limitation the rights |
| 6 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | +# copies of the Software, and to permit persons to whom the Software is |
| 8 | +# furnished to do so, subject to the following conditions: |
| 9 | +# |
| 10 | +# The above copyright notice and this permission notice shall be included in all |
| 11 | +# copies or substantial portions of the Software. |
| 12 | +# |
| 13 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 | +# SOFTWARE. |
| 20 | + |
| 21 | +name: 'Clear Cache if Labeled' |
| 22 | +description: 'Check if PR has specific backend ClearCache label and clear cache if present' |
| 23 | + |
| 24 | +inputs: |
| 25 | + github-token: |
| 26 | + description: 'GitHub token for API access' |
| 27 | + required: true |
| 28 | + backend: |
| 29 | + description: 'The backend name to check for (e.g., mthreads)' |
| 30 | + required: true |
| 31 | + |
| 32 | +runs: |
| 33 | + using: 'composite' |
| 34 | + steps: |
| 35 | + - name: Check specific ClearCache label |
| 36 | + id: check |
| 37 | + uses: actions/github-script@v6 |
| 38 | + with: |
| 39 | + github-token: ${{ inputs.github-token }} |
| 40 | + script: | |
| 41 | + const backend = '${{ inputs.backend }}'; |
| 42 | + const expectedLabel = `ClearCache:${backend}`; |
| 43 | +
|
| 44 | + if (context.eventName !== 'pull_request' && context.eventName !== 'pull_request_target') { |
| 45 | + console.log('ℹ️ Not a PR event, skipping label check'); |
| 46 | + core.setOutput('has_clear_cache_label', 'false'); |
| 47 | + return; |
| 48 | + } |
| 49 | +
|
| 50 | + if (!context.payload || !context.payload.pull_request) { |
| 51 | + console.log('⚠️ No pull_request payload found, skipping label check'); |
| 52 | + core.setOutput('has_clear_cache_label', 'false'); |
| 53 | + return; |
| 54 | + } |
| 55 | +
|
| 56 | + const prNumber = context.payload.pull_request.number; |
| 57 | + try { |
| 58 | + const { data: prData } = await github.rest.pulls.get({ |
| 59 | + owner: context.repo.owner, |
| 60 | + repo: context.repo.repo, |
| 61 | + pull_number: prNumber |
| 62 | + }); |
| 63 | +
|
| 64 | + const labels = (prData.labels || []).map(label => label.name); |
| 65 | + console.log(`Current PR labels:`, labels.join(', ') || '(no labels)'); |
| 66 | +
|
| 67 | + const hasClearCache = labels.includes(expectedLabel); |
| 68 | + console.log(`🔍 Has "${expectedLabel}" label:`, hasClearCache ? '✅ YES' : '❌ NO'); |
| 69 | +
|
| 70 | + core.setOutput('has_clear_cache_label', hasClearCache ? 'true' : 'false'); |
| 71 | + } catch (err) { |
| 72 | + console.log('❌ Error checking PR labels:', err.message || err); |
| 73 | + core.setOutput('has_clear_cache_label', 'false'); |
| 74 | + } |
| 75 | +
|
| 76 | + - name: Clear cache if label present |
| 77 | + id: cleanup |
| 78 | + if: steps.check.outputs.has_clear_cache_label == 'true' |
| 79 | + shell: bash |
| 80 | + run: | |
| 81 | + echo "=========================================" |
| 82 | + echo "🧹 Clearing cache for ${{ inputs.backend }} backend." |
| 83 | + echo "=========================================" |
| 84 | +
|
| 85 | + echo "-> Clearing cache..." |
| 86 | + echo "-> Remove ~/.triton/cache" |
| 87 | + rm -rf ~/.triton/cache || true |
| 88 | + echo "-> Remove ~/.flaggems" |
| 89 | + rm -rf ~/.flaggems || true |
| 90 | + echo "-> Clear cache done" |
0 commit comments