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

feat(github): point to ref/repo from PR HEAD, add/remove labels #10

Merged
merged 3 commits into from
Jan 17, 2025
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
60 changes: 60 additions & 0 deletions .github/workflows/github-add-label.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: github-add-label

on:
workflow_call:
inputs:
PRIMUS_REF:
description: 'The primus ref to checkout.'
required: true
default: 'main'
type: string
Comment on lines +6 to +10
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove default value for required input.

The PRIMUS_REF input is marked as required but also has a default value. This is redundant as the default value will never be used for required inputs.

       PRIMUS_REF:
         description: 'The primus ref to checkout.'
         required: true
-        default: 'main'
         type: string
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
PRIMUS_REF:
description: 'The primus ref to checkout.'
required: true
default: 'main'
type: string
PRIMUS_REF:
description: 'The primus ref to checkout.'
required: true
type: string
🧰 Tools
🪛 actionlint (1.7.4)

9-9: input "PRIMUS_REF" of workflow_call event has the default value "main", but it is also required. if an input is marked as required, its default value will never be used

(events)

GITHUB_LABEL_NAME:
description: 'The name of the label to add.'
required: true
type: string

defaults:
run:
shell: bash

env:
PRIMUS_HOME: .primus
MAKE: make --no-print-directory --makefile=.primus/src/make/main.mk

jobs:
signoz:
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: self-checkout
uses: actions/checkout@v4
- id: token
name: github-token-gen
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.PRIMUS_APP_ID }}
private-key: ${{ secrets.PRIMUS_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- name: primus-checkout
uses: actions/checkout@v4
with:
repository: signoz/primus
ref: ${{ inputs.PRIMUS_REF }}
path: .primus
token: ${{ steps.token.outputs.token }}
- name: info
run: |
$MAKE info
- name: add-label
env:
GH_REPOSITORY: ${{ github.repository }}
GH_ISSUE_NUMBER: ${{ github.event.issue.number }}
GH_LABEL_NAME: ${{ inputs.GITHUB_LABEL_NAME }}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

The workflow needs context validation or parameter adjustment

The workflow is designed as a reusable workflow (workflow_call trigger) but assumes github.event.issue.number will always be available. This assumption is unsafe as:

  • Pull requests use github.event.pull_request.number instead
  • Other event contexts might not have an issue number
  • As a reusable workflow, it could be called from various event contexts

Consider either:

  • Adding the number as an input parameter
  • Adding context validation
  • Handling different event types (issues/PRs) appropriately
🔗 Analysis chain

Verify issue number availability in event context.

The workflow assumes github.event.issue.number will be available, but this might not be true for all trigger contexts (e.g., PRs vs Issues).

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the workflow is used in any other workflow files
# to understand the trigger contexts

echo "Checking workflow usage contexts..."
rg -l "uses: ./.github/workflows/github-add-label.yaml" .

Length of output: 140


Script:

#!/bin/bash
# First, let's look at the workflow file content
echo "=== Workflow File Content ==="
cat .github/workflows/github-add-label.yaml

echo -e "\n=== Searching for workflow references with different patterns ==="
rg -l "github-add-label" .

echo -e "\n=== Looking for workflow files that might use this ==="
fd "workflow" .github/

Length of output: 2060


Script:

#!/bin/bash
# Search for workflow files that might call this workflow
echo "=== Searching for workflow calls ==="
rg -l "workflow.*github-add-label" .github/workflows/

# Look for the actual workflow call pattern
echo -e "\n=== Searching for specific workflow call patterns ==="
rg "uses:.*github-add-label" .github/workflows/

Length of output: 311

run: |
$MAKE github-add-label \
GITHUB_ARGS="-t ${{ steps.token.outputs.token }} \
-r ${GH_REPOSITORY} \
-i ${GH_ISSUE_NUMBER} \
-l '${GH_LABEL_NAME}'"
60 changes: 60 additions & 0 deletions .github/workflows/github-remove-label.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: github-remove-label

on:
workflow_call:
inputs:
PRIMUS_REF:
description: 'The primus ref to checkout.'
required: true
default: 'main'
type: string
GITHUB_LABEL_NAME:
description: 'The name of the label to remove.'
required: true
type: string

defaults:
run:
shell: bash

env:
PRIMUS_HOME: .primus
MAKE: make --no-print-directory --makefile=.primus/src/make/main.mk

jobs:
signoz:
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: self-checkout
uses: actions/checkout@v4
- id: token
name: github-token-gen
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.PRIMUS_APP_ID }}
private-key: ${{ secrets.PRIMUS_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- name: primus-checkout
uses: actions/checkout@v4
with:
repository: signoz/primus
ref: ${{ inputs.PRIMUS_REF }}
path: .primus
token: ${{ steps.token.outputs.token }}
- name: info
run: |
$MAKE info
- name: remove-label
env:
GH_REPOSITORY: ${{ github.repository }}
GH_ISSUE_NUMBER: ${{ github.event.issue.number }}
GH_LABEL_NAME: ${{ inputs.GITHUB_LABEL_NAME }}
run: |
$MAKE github-remove-label \
GITHUB_ARGS="-t ${{ steps.token.outputs.token }} \
-r ${GH_REPOSITORY} \
-i ${GH_ISSUE_NUMBER} \
-l '${GH_LABEL_NAME}'"
3 changes: 3 additions & 0 deletions .github/workflows/go-fmt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
steps:
- name: self-checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- id: token
name: github-token-gen
uses: actions/create-github-app-token@v1
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/go-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
steps:
- name: self-checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- id: token
name: github-token-gen
uses: actions/create-github-app-token@v1
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
steps:
- name: self-checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- id: token
name: github-token-gen
uses: actions/create-github-app-token@v1
Expand Down