Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write github actions needed for auto closing issues opened beyond core #639

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ locals_without_parens =
[
inputs: [
"{lib,test,config,benchmark}/**/*.{ex,exs}",
"scripts/*.exs",
"*.exs"
],
locals_without_parens: locals_without_parens,
Expand Down
39 changes: 39 additions & 0 deletions .github/actions/close_issue/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: 'Close issue when opened'
description: 'Closes a newly opened issue, tags it and puts it in the proper column in Smackore project board.'
inputs:
GITHUB_TOKEN:
description: 'GitHub token'
required: true
ISSUE_URL:
description: 'Issue URL'
required: true
ISSUE_NUMBER:
description: 'Issue number'
required: true
REPOSITORY:
description: 'Repository'
required: true
runs:
using: 'composite'
steps:
- name: Setup Elixir
uses: erlef/setup-beam@v1
with:
otp-version: '26.1'
elixir-version: '1.15.6'
- name: Checkout code
uses: actions/checkout@v3
- name: Create ticket and close issue
run: |
gh issue edit $ISSUE_URL --add-project "Smackore" --add-label closed-by-membrane-bot
sleep 10
export TICKET_ID=$(gh project item-list 19 --owner membraneframework --format json --limit 10000000 | elixir get_ticket_id.exs "$ISSUE_URL" | awk '/TICKET_ID/{print $2}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export TICKET_ID=$(gh project item-list 19 --owner membraneframework --format json --limit 10000000 | elixir get_ticket_id.exs "$ISSUE_URL" | awk '/TICKET_ID/{print $2}')
export TICKET_ID=$(gh project item-list 19 --owner membraneframework --format json --limit 10000000 | elixir get_ticket_id.exs "$ISSUE_URL")

why not just print ticket id without unnecessary stuff?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because .exs script sometimes prints also logs from Mix.install/1, like Resolving Hex dependencies...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that's another reason not to go with Elixir here ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could set MIX_QUIET=1, though it seems it doesn't work for Mix.install :P It may be worth to report an issue though

mkaput marked this conversation as resolved.
Show resolved Hide resolved
gh issue close $ISSUE_URL --comment "Only PRs welcome ;)" --reason "not planned"
mkaput marked this conversation as resolved.
Show resolved Hide resolved
sleep 10
gh project item-edit --id "$TICKET_ID" --field-id PVTSSF_lADOAYE_z84AWEIBzgOGd1k --project-id PVT_kwDOAYE_z84AWEIB --single-select-option-id "fa223107"
env:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
ISSUE_URL: ${{ inputs.ISSUE_URL }}
ISSUE_NUMBER: ${{ inputs.ISSUE_NUMBER }}
REPOSITORY: ${{ inputs.REPOSITORY }}
shell: bash
14 changes: 14 additions & 0 deletions .github/actions/create_label/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'Create label'
description: 'Creates a label closed-by-membrane-bot, if it does not exist.'
inputs:
GITHUB_TOKEN:
description: 'GitHub token'
required: true
runs:
using: 'composite'
steps:
- run: |
gh label create closed-by-membrane-bot --description "Automatically closed by Membrane bot" --color EB3467 || true
env:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
shell: bash
2 changes: 1 addition & 1 deletion .github/workflows/update-packages-list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
env:
GH_TOKEN: ${{ secrets.BOT_TOKEN }}
run: |
elixir update_packages_list.exs
elixir scripts/update_packages_list.exs
git config user.name 'Membrane Bot'
git config user.email '[email protected]'
git checkout -B auto-update-packages-list
Expand Down
23 changes: 23 additions & 0 deletions scripts/get_ticket_id.exs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python is preinstalled in GH actions, why not just use it or jq ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to use it instead of elixir?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, setup-elixir is just an unnecessary cost here

Copy link
Member Author

@FelonEkonom FelonEkonom Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But does this cost hurt us anyhow?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frustration that action is working longer than it should. I don't think you'll saturate concurrency limits, given this runs on Linux runners only.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This script is used by .github/actions/close_issue/action.yml and it shouldn't be used in any other places.

# It expects:
# - output from `$ gh project item-list <project_id> --owner <owner> --format json --limit <limit>` command
# on standard input
# - URL of issue, that corresponds to one of the tickets included in the JSON data returned from the command
# above. This URL should be passed as an argument in argv
# And prints `TICKET_ID <id>` on standard output, where `<id>` is id of a project item corresponding to the
# issue with the specified URL. Note, that beyond this, stdout can also contain some logs from `Mix.install/1`,
# e.g. `Resolving Hex dependencies...`.

Mix.install(json: "~> 1.4.1")

[issue_url] = System.argv()

:ok =
IO.read(:stdio, :eof)
|> JSON.decode!()
|> Map.get("items")
|> Enum.find(&(&1["content"]["url"] == issue_url))
|> Map.get("id")
|> then(&"\nTICKET_ID #{&1}\n")
|> IO.puts()
File renamed without changes.