Skip to content

Commit

Permalink
[GitHub] Fix action using github.context (#4456)
Browse files Browse the repository at this point in the history
* [GitHub] Fix action using github.context

* use the post-discord-message.py script to avoid msg embeds

* change github.context.payload.pull_request.action

* test bot name using context

* test message

* Update post-github-activity.yml

* Update post-github-activity.yml

* Update post-github-activity.yml

* Update post-github-activity.yml

* Update post-github-activity.yml

* Update post-github-activity.yml

* Update post-github-activity.yml

* Update post-github-activity.yml

* fix all variable uses

* fix wrong merge

* fix use of removed function

* fix pending-discussion

* test empty embeds

* last test in embeds

* propagate the use of github.event

* forgotten github.event to propagate

* if using multiple conditions

* Test list of events instead of array

* Update post-github-activity.yml

* Update post-github-activity.yml

* Update post-github-activity.yml

* Update post-github-activity.yml

* Update post-github-activity.yml

* Update post-github-activity.yml

* fix no embeds, now working!

* minor cosmetic

* split action for GH activities in three different files

* rename created actions

* simplify action conditions

* fix use of user.login, fix PR trigger and cosmetic

* fix cases where no embeds is given

* fix python if

* add stargazer name mention

* test new if condition in action

* update all if condition in the same way

* attempt to fix if condition

* update message reviewers

* it works : good condition for if condition

* fix message for thanking reviewers

* use * for arrays

* reformat message

* use to join function

* apply a if condition to all actions to apply ONLY on sofa-framework

* Apply suggestions from code review

* Update .github/workflows/post-release.yml

Co-authored-by: Paul Baksic <[email protected]>

---------

Co-authored-by: Paul Baksic <[email protected]>
  • Loading branch information
hugtalbot and bakpaul authored Jan 26, 2024
1 parent 5288d25 commit 1e0df59
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 121 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/post-agenda-sofa-dev-meeting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
schedule:
- cron: '30 7 * * 1' # 9:30 am CET every Monday
- cron: '0 6 * * 3' # 8:00 am CET on Wednesdays

jobs:
run:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'sofa-framework' }}

steps:
- name: Check out code
Expand All @@ -21,21 +23,21 @@ jobs:

# Monday message : agenda
- name: Run script post-discord-message.py
if: ${{ github.event_name == 'schedule' && github.event.scheduled_time | date('%-u') == '1' }}
if: ${{ github.event.scheduled_time | date('%-u') == '1' }}
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_MAIN_WEBHOOK_URL }}
MESSAGE : ":sunrise: Morning, dear SOFA community! Next Wednesday takes place the weekly SOFA dev meeting:\n**_Any specific topic to share or to discuss?_** If so, please reply in this thread :speech_balloon: *Remember you can use the tag \"pr: dev meeting topic\" for your PRs*"
MESSAGE : ":sunrise: Morning, dear SOFA community! Next Wednesday takes place the weekly SOFA dev meeting:\n**_Any specific topic to share or to discuss?_** If so, please reply in this thread :speech_balloon: *Remember you can use the tag \"pr: dev meeting topic\" for your PRs*"
BOT_NAME: "Meeting reminder"
EMBEDS_TITLE: "Label \"pr: dev-meeting topic\""
EMBEDS_URL: "https://github.com/sofa-framework/sofa/labels/pr%3A%20dev%20meeting%20topic"
EMBEDS_DESCRIPTION: ""

# Wednesday message : get ready
- name: Run script post-discord-message.py
if: ${{ github.event_name == 'schedule' && github.event.scheduled_time | date('%-u') == '3' }}
if: ${{ github.event.scheduled_time | date('%-u') == '3' }}
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/post-announcements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,36 @@ name: Post - Announcement GHD topics

on:
discussion:
types: [created]
types:
- created

jobs:
run:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'sofa-framework' }}

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Install dependencies
if: ( context.payload.discussion.category.name == 'Announcement' ) || ( context.payload.discussion.category.name == 'Share your achievements' )
if: ( github.event.discussion.category.name == 'Announcement' ) || ( github.event.discussion.category.name == 'Share your achievements' )
run: |
pip install python-graphql-client
pip install python-dateutil
pip install requests
working-directory: ${{ github.workspace }}

- name: Run script post-discord-message.py
if: ( context.payload.discussion.category.name == 'Announcement' ) || ( context.payload.discussion.category.name == 'Share your achievements' )
if: ( github.event.discussion.category.name == 'Announcement' ) || ( github.event.discussion.category.name == 'Share your achievements' )
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_ANNOUNCEMENTS_WEBHOOK_URL }}
MESSAGE: ":loudspeaker: New post \"${{context.payload.discussion.category.name}}\" :arrow_right: **[${{context.payload.discussion.title}}](https://github.com/sofa-framework/sofa/discussions/${{context.payload.discussion.number}})** by [${{context.payload.discussion.author.login}}](https://github.com/${{context.payload.discussion.author.login}})"
MESSAGE: ":loudspeaker: New post \"${{github.event.discussion.category.name}}\" :arrow_right: **[${{github.event.discussion.title}}](https://github.com/sofa-framework/sofa/discussions/${{github.event.discussion.number}})** by [${{github.event.discussion.author.login}}](https://github.com/${{github.event.discussion.author.login}})"
BOT_NAME: "Discussion announcement"
EMBEDS_TITLE: ${{context.payload.discussion.title}}
EMBEDS_URL: "https://github.com/sofa-framework/sofa/discussions/${{context.payload.discussion.number}}"
EMBEDS_TITLE: "${{github.event.discussion.title}}"
EMBEDS_URL: "https://github.com/sofa-framework/sofa/discussions/${{github.event.discussion.number}}"
EMBEDS_DESCRIPTION: ""

35 changes: 35 additions & 0 deletions .github/workflows/post-github-activity-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Post - Github activity (issues)

on:
issues:
types:
- opened

jobs:
run:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'sofa-framework' }}

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Install dependencies
run: |
pip install python-graphql-client
pip install python-dateutil
pip install requests
working-directory: ${{ github.workspace }}

# Issue related event
- name: Run script post-discord-message.py for Issue opened
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_MAIN_WEBHOOK_URL }}
MESSAGE: ":space_invader: New issue raised \"[${{github.event.issue.title}}](https://github.com/sofa-framework/sofa/issues/${{github.event.issue.number}})\" by [@${{github.event.issue.user.login}}](https://github.com/${{github.event.issue.user.login}})"
BOT_NAME: "SOFA Github bot"
EMBEDS_TITLE: "${{github.event.issue.title}} (#${{github.event.issue.number}})"
EMBEDS_URL: "https://github.com/sofa-framework/sofa/issues/${{github.event.issue.number}}"
EMBEDS_DESCRIPTION: ""
66 changes: 66 additions & 0 deletions .github/workflows/post-github-activity-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Post - Github activity (PRs)

on:
pull_request:
types:
- opened
- review_requested
- closed

jobs:
run:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'sofa-framework' }}

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Install dependencies
run: |
pip install python-graphql-client
pip install python-dateutil
pip install requests
working-directory: ${{ github.workspace }}

# PR opened
- name: Run script post-discord-message.py for PR opened (main)
if: ${{ github.event.action == 'opened' }}
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_MAIN_WEBHOOK_URL }}
MESSAGE: ":new: PR opened: [#${{github.event.pull_request.number}} ${{github.event.pull_request.title}}](https://github.com/sofa-framework/sofa/pull/${{github.event.pull_request.number}})"
BOT_NAME: "SOFA Github bot"
EMBEDS_TITLE: "#${{github.event.pull_request.number}} ${{github.event.pull_request.title}}"
EMBEDS_URL: "https://github.com/sofa-framework/sofa/pull/${{github.event.pull_request.number}}"
EMBEDS_DESCRIPTION: "Authored by @${{github.event.pull_request.user.login}}\nLabels: ${{ join(github.event.pull_request.labels.*.name, ', ') }}"

# PR merged
- name: Run script post-discord-message.py for PR merged
if: ${{ github.event.action == 'closed' && github.event.pull_request.merged == true }}
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_MAIN_WEBHOOK_URL }}
MESSAGE: ":raised_hands: Thanks [@${{github.event.pull_request.merged_by.login}}](https://github.com/${{github.event.pull_request.merged_by.login}}) for merging PR [#${{github.event.pull_request.number}} ${{github.event.pull_request.title}}](https://github.com/sofa-framework/sofa/pull/${{github.event.pull_request.number}}) authored by @${{github.event.pull_request.user.login}}"
BOT_NAME: "SOFA Github bot"
EMBEDS_TITLE: ""
EMBEDS_URL: ""
EMBEDS_DESCRIPTION: ""

# PR review requested event
- name: Run script post-discord-message.py for PR review request
if: ${{ github.event.action == 'review_requested' }}
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_MAIN_WEBHOOK_URL }}
MESSAGE: ":eyeglasses: Review requested: join(github.event.pull_request.requested_reviewers.*.login, ', ') would you please review [#${{github.event.pull_request.number}}](https://github.com/sofa-framework/sofa/pull/${{github.event.pull_request.number}})?"
BOT_NAME: "SOFA Github bot"
EMBEDS_TITLE: ""
EMBEDS_URL: ""
EMBEDS_DESCRIPTION: ""
35 changes: 35 additions & 0 deletions .github/workflows/post-github-activity-star.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Post - Github activity (stars)

on:
watch:
types: [started]

jobs:
run:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'sofa-framework' }}

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Install dependencies
run: |
pip install python-graphql-client
pip install python-dateutil
pip install requests
working-directory: ${{ github.workspace }}

# Star/watch related event
- name: Run script post-discord-message.py for stars
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_MAIN_WEBHOOK_URL }}
MESSAGE: ":fire: :fire: Come ON :fire: :fire: \nOne new :star: for SOFA on Github!"
BOT_NAME: "SOFA Github bot"
EMBEDS_TITLE: ""
EMBEDS_URL: ""
EMBEDS_DESCRIPTION: ""

95 changes: 0 additions & 95 deletions .github/workflows/post-github-activity.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/post-pending-discussions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
jobs:
run:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'sofa-framework' }}

steps:
- name: Check out code
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/post-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
jobs:
run:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'sofa-framework' }}

steps:
- name: Check out code
Expand All @@ -26,10 +27,10 @@ jobs:
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_ANNOUNCEMENTS_WEBHOOK_URL }}
MESSAGE: ":loudspeaker: **New SOFA release** :loudspeaker: \n > SOFA ${{context.payload.release.name}} is now available, [check it out](https://github.com/sofa-framework/sofa/releases/tag/${{context.payload.release.tag_name}})! \n > For more, see the [ChangeLog](https://github.com/sofa-framework/sofa/blob/${{context.payload.release.tag_name}}/CHANGELOG.md) \n \n Thanks to all contributors!"
MESSAGE: ":loudspeaker: **New SOFA release** :loudspeaker: \n > SOFA ${{github.event.release.name}} is now available, [check it out](https://github.com/sofa-framework/sofa/releases/tag/${{github.event.release.tag_name}})! \n > For more insights, see the [ChangeLog](https://github.com/sofa-framework/sofa/blob/${{github.event.release.tag_name}}/CHANGELOG.md) \n \n Thanks to all contributors!"
BOT_NAME: "Release announcement"
EMBEDS_TITLE: "SOFA ${{context.payload.release.name}}"
EMBEDS_URL: "https://github.com/sofa-framework/sofa/releases/tag/${{context.payload.release.tag_name}}"
EMBEDS_TITLE: "SOFA ${{github.event.release.name}}"
EMBEDS_URL: "https://github.com/sofa-framework/sofa/releases/tag/${{github.event.release.tag_name}}"
EMBEDS_DESCRIPTION: "New source and binary release of SOFA"


1 change: 1 addition & 0 deletions .github/workflows/pr-label-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
name: Check labels
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'sofa-framework' }}

steps:
- name: Delay for 10 Seconds
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr-timing-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
check_labels:
name: Check labels
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'sofa-framework' }}

steps:
- name: Check Labels and Age
id: check_labels_and_comment
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/pr-title-checker.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
name: PR check - Title
on:
pull_request:
types: [opened, synchronize, edited, reopened]
types:
- opened
- synchronize
- edited
- reopened

jobs:
check_title:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'sofa-framework' }}

steps:
- name: Check Pull Request Title
id: title_check
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/stale_github_discussions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
jobs:
run:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'sofa-framework' }}

steps:
- name: Check out code
Expand Down
Loading

0 comments on commit 1e0df59

Please sign in to comment.