|
1 | 1 | name: Update Library |
| 2 | + |
2 | 3 | on: |
3 | 4 | issues: |
4 | | - types: [opened] |
| 5 | + types: [opened, edited] # Trigger on new and edited issues |
5 | 6 |
|
6 | 7 | jobs: |
7 | 8 | update: |
8 | 9 | runs-on: ubuntu-latest |
9 | 10 | permissions: |
10 | | - contents: write # Grant write permissions |
| 11 | + contents: write # Needed to push changes |
| 12 | + issues: write # Needed to comment on issues |
| 13 | + |
11 | 14 | steps: |
12 | 15 | - name: Checkout repository |
13 | | - uses: actions/checkout@v2 |
| 16 | + uses: actions/checkout@v3 |
14 | 17 |
|
15 | 18 | - name: Set up Python |
16 | | - uses: actions/setup-python@v2 |
| 19 | + uses: actions/setup-python@v4 |
17 | 20 | with: |
18 | 21 | python-version: '3.x' |
19 | 22 |
|
20 | | - - name: Install dependencies |
21 | | - run: | |
22 | | - python -m pip install --upgrade pip |
23 | | - |
24 | | - |
25 | 23 | - name: Run Python script |
26 | 24 | env: |
27 | 25 | ISSUE_BODY: ${{ github.event.issue.body }} |
28 | | - run: | |
29 | | - python update_library.py |
| 26 | + run: python update_library.py |
30 | 27 |
|
31 | 28 | - name: Commit changes |
| 29 | + if: success() |
32 | 30 | run: | |
33 | 31 | git config --global user.name "github-actions" |
34 | 32 | git config --global user.email "actions@github.com" |
35 | 33 | git add data/library.json data/library.csv |
36 | | - git commit -m "Update library data" |
37 | | - git push origin HEAD:${{ github.ref }} |
38 | | - - name: Close issue |
| 34 | + git commit -m "Update library data" || echo "No changes to commit" |
| 35 | + git push origin main |
| 36 | +
|
| 37 | + - name: Close issue on success |
39 | 38 | if: success() && github.event.issue.state == 'open' |
40 | | - uses: peter-evans/close-issue@v2 |
| 39 | + uses: peter-evans/close-issue@v2 |
41 | 40 | with: |
42 | 41 | issue-number: ${{ github.event.issue.number }} |
43 | | - comment: "Library updated successfully and issue closed." |
44 | | - reason: completed |
45 | | - - name: Handle failure |
46 | | - if: failure() |
| 42 | + comment: "✅ Library updated successfully and issue closed." |
| 43 | + reason: completed |
| 44 | + |
| 45 | + - name: Comment on failure |
| 46 | + if: failure() |
47 | 47 | uses: actions/github-script@v6 |
48 | 48 | with: |
49 | 49 | script: | |
50 | 50 | const issue_number = context.payload.issue.number; |
51 | | - const comment = "There was an error updating the library. Please check the logs for details."; |
| 51 | + const body = "⚠️ Validation failed. Please submit valid JSON with `barcode`, `user`, and `action` fields."; |
52 | 52 | await github.issues.createComment({ |
53 | 53 | ...context.repo, |
54 | 54 | issue_number, |
55 | | - body: comment |
| 55 | + body |
56 | 56 | }); |
57 | 57 | await github.issues.update({ |
58 | 58 | ...context.repo, |
|
0 commit comments