Skip to content

Commit

Permalink
Fix PR Metadata and Downstream issues (#1466,#1468,#1469)
Browse files Browse the repository at this point in the history
Co-authored-by: Trajan0x <[email protected]>
  • Loading branch information
trajan0x and trajan0x authored Oct 20, 2023
1 parent dcda614 commit 8852be5
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 41 deletions.
18 changes: 18 additions & 0 deletions .github/actions/add-label/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Add Label

This action adds a specified label to an issue or pull request.

## Inputs
* `issue_number`: The issue number derived from the event payload. Default is `${{ github.event.number }}` then `${{ github.event.issue.number }}`. Action will fail if neither of these is present. If you need to use this action on a push event (or any event not associated directly with an `issue` or `pull_request`, please see [gh-find-current-pr](https://github.com/jwalton/gh-find-current-pr))
* `label`: The label to add to the issue


## Usage:

```yaml
- name: Add Label
uses: ./.github/actions/add-label
with:
label: 'needs-go-generate-${{matrix.package}}'
issue-number: ${{github.event.number}}
```
43 changes: 43 additions & 0 deletions .github/actions/add-label/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Add Label
description: Add a label to the issue or pull request
inputs:
issue_number:
description: 'The issue number to associate with. Defaults to the current issue or pull request number used to trigger the action.'
required: false
default: ''
label:
description: 'The label to add.'
required: true

runs:
using: 'composite'
steps:
# # TODO, dedupe w/ remove-label
- name: Resolve issue number
id: resolve_issue_number
run: |
if [[ -n '${{ inputs.issue_number }}' ]]; then
echo 'Using input issue number: ${{ inputs.issue_number }}'
echo '::set-output name=issue::${{ inputs.issue_number }}'
elif [[ -n '${{ github.event.number }}' ]]; then
echo 'Using event number: ${{ github.event.number }}'
echo '::set-output name=issue::${{ github.event.number }}'
elif [[ -n '${{ github.event.issue.number }}' ]]; then
echo 'Using event issue number: ${{ github.event.issue.number }}'
echo '::set-output name=issue::${{ github.event.issue.number }}'
else
echo 'Could not determine issue number'
exit 1
fi
shell: bash

- name: Add Label
uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: ${{ steps.resolve_issue_number.outputs.issue }},
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['${{ inputs.label }}']
})
16 changes: 16 additions & 0 deletions .github/actions/remove-label/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Remove Label

This action removes a specified label to an issue or pull request.

## Inputs
* `issue_number`: The issue number derived from the event payload. Default is `${{ github.event.number }}` then `${{ github.event.issue.number }}`. Action will fail if neither of these is present. If you need to use this action on a push event (or any event not associated directly with an `issue` or `pull_request`, please see [gh-find-current-pr](https://github.com/jwalton/gh-find-current-pr))
* `label`: The label to add to the issue


```yaml
- name: Remove Label
uses: ./.github/actions/remove-label
with:
label: 'needs-go-generate-${{matrix.package}}'
issue-number: ${{github.event.number}}
```
43 changes: 43 additions & 0 deletions .github/actions/remove-label/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Remove Label
description: Remove a label to the issue or pull request
inputs:
issue_number:
description: 'The issue number to associate with. Defaults to the current issue or pull request number used to trigger the action.'
required: false
default: ''
label:
description: 'The label to add.'
required: true

runs:
using: 'composite'
steps:
# TODO, dedupe w/ add-label
- name: Resolve issue number
id: resolve_issue_number
run: |
if [[ -n '${{ inputs.issue_number }}' ]]; then
echo 'Using input issue number: ${{ inputs.issue_number }}'
echo '::set-output name=issue::${{ inputs.issue_number }}'
elif [[ -n '${{ github.event.number }}' ]]; then
echo 'Using event number: ${{ github.event.number }}'
echo '::set-output name=issue::${{ github.event.number }}'
elif [[ -n '${{ github.event.issue.number }}' ]]; then
echo 'Using event issue number: ${{ github.event.issue.number }}'
echo '::set-output name=issue::${{ github.event.issue.number }}'
else
echo 'Could not determine issue number'
exit 1
fi
shell: bash

- name: Remove Label
uses: actions/github-script@v6
with:
script: |
github.rest.issues.removeLabel({
issue_number: ${{ steps.resolve_issue_number.outputs.issue }},
owner: context.repo.owner,
repo: context.repo.repo,
name: ['${{ inputs.label }}']
})
5 changes: 5 additions & 0 deletions .github/actions/setup-nodejs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ runs:
shell: bash
id: nvmrc

- name: Setup Globals
shell: bash
run: |
echo "enableGlobalCache true" >> ~/.yarnrc
- uses: actions/setup-node@v3
with:
node-version: '${{ steps.nvmrc.outputs.NVMRC }}'
Expand Down
53 changes: 22 additions & 31 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,15 @@ jobs:
needs: cancel-outdated
# currently, this matches the logic in the go generate check. If we ever add more checks that run on all packages, we should
# change this to run on those pushes
if: ${{ github.event_name != 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) != github.ref }}
if: ${{ github.event_name != 'push' && format('refs/heads/{0}', github.event.repository.default_branch) != github.ref }}
outputs:
issue_number: ${{ steps.find_pr.outputs.pr }}
metadata: ${{ steps.metadata.outputs.METADATA }}
labels: ${{ steps.metadata.outputs.LABELS }}
steps:
- uses: jwalton/gh-find-current-pr@v1
id: find_pr
# TODO: https://stackoverflow.com/a/75429845 consider splitting w/ gql to reduce limit hit
- run: |
- name: Fetch Metadata for ${{github.event.number}}
run: |
# Fetch the metadata
metadata="$(gh api repos/$OWNER/$REPO_NAME/pulls/$PULL_REQUEST_NUMBER)"
Expand All @@ -380,15 +379,15 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
PULL_REQUEST_NUMBER: ${{ steps.find_pr.outputs.pr }}
PULL_REQUEST_NUMBER: ${{github.event.number}}

# check if we need to rerun go generate as a result of solidity changes. Note, this will only run on solidity changes.
# TODO: consolidate w/ go change check. This will run twice on agents
check-generation-solidity:
name: Go Generate (Solidity Only)
runs-on: ubuntu-latest
needs: [changes, pr_metadata]
if: ${{ github.event_name != 'pull_request' && needs.changes.outputs.solidity_changes == 'true' }}
if: ${{ github.event_name != 'push' && needs.changes.outputs.solidity_changes == 'true' }}
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -472,48 +471,44 @@ jobs:
# TODO: this can run into a bit of a race condition if any other label is removed/added while this is run, look into fixing this by dispatching another workflow
- name: Add Label
if: ${{ !contains(fromJson(needs.pr_metadata.outputs.labels), format('needs-go-generate-{0}', matrix.package)) && steps.verify-changed-files.outputs.files_changed == 'true' }}
uses: andymckay/labeler@3a4296e9dcdf9576b0456050db78cfd34853f260
uses: ./.github/actions/add-label
with:
add-labels: 'needs-go-generate-${{matrix.package}}'
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ needs.pr_metadata.outputs.issue_number }}
label: 'needs-go-generate-${{matrix.package}}'

- name: Remove Label
if: ${{ contains(fromJson(needs.pr_metadata.outputs.labels), format('needs-go-generate-{0}', matrix.package)) && steps.verify-changed-files.outputs.files_changed != 'true' }}
uses: andymckay/labeler@3a4296e9dcdf9576b0456050db78cfd34853f260
uses: ./.github/actions/remove-label
with:
remove-labels: 'needs-go-generate-${{matrix.package}}'
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ needs.pr_metadata.outputs.issue_number }}
label: 'needs-go-generate-${{matrix.package}}'

remove-label-generation:
name: Remove Generate Label From Unused Jobs
runs-on: ubuntu-latest
needs: [changes, pr_metadata]
if: ${{ github.event_name != 'pull_request' && needs.changes.outputs.unchanged_package_count_deps > 0 && contains(needs.pr_metadata.outputs.labels, 'needs-go-generate') }}
if: ${{ github.event_name != 'push' && needs.changes.outputs.unchanged_package_count_deps > 0 && contains(needs.pr_metadata.outputs.labels, 'needs-go-generate') }}
strategy:
fail-fast: false
max-parallel: 1
matrix:
# only do on agents for now. Anything that relies on solidity in a package should do this
package: ${{ fromJSON(needs.changes.outputs.unchanged_deps) }}
steps:
# needed for remove label action
- uses: actions/checkout@v4
if: ${{ contains(fromJson(needs.pr_metadata.outputs.labels), format('needs-go-generate-{0}', matrix.package)) }}
with:
fetch-depth: 1
- name: Remove Label
if: ${{ contains(fromJson(needs.pr_metadata.outputs.labels), format('needs-go-generate-{0}', matrix.package)) }}
# labels can't be removed in parallel
uses: andymckay/labeler@3a4296e9dcdf9576b0456050db78cfd34853f260
uses: ./.github/actions/remove-label
with:
remove-labels: 'needs-go-generate-${{matrix.package}}'
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ needs.pr_metadata.outputs.issue_number }}

label: 'needs-go-generate-${{matrix.package}}'


check-generation:
name: Go Generate (Module Changes)
runs-on: ubuntu-latest
needs: [changes, pr_metadata]
if: ${{ github.event_name != 'pull_request' && needs.changes.outputs.package_count_deps > 0 }}
if: ${{ github.event_name != 'push' && needs.changes.outputs.package_count_deps > 0 }}
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -635,16 +630,12 @@ jobs:
# TODO: this can run into a bit of a race condition if any other label is removed/added while this is run, look into fixing this by dispatching another workflow
- name: Add Label
if: ${{ !contains(fromJson(needs.pr_metadata.outputs.labels), format('needs-go-generate-{0}', matrix.package)) && steps.verify-changed-files.outputs.files_changed == 'true' }}
uses: andymckay/labeler@3a4296e9dcdf9576b0456050db78cfd34853f260
uses: ./.github/actions/add-label
with:
add-labels: 'needs-go-generate-${{matrix.package}}'
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ needs.pr_metadata.outputs.issue_number }}
label: 'needs-go-generate-${{matrix.package}}'

- name: Remove Label
if: ${{ contains(fromJson(needs.pr_metadata.outputs.labels), format('needs-go-generate-{0}', matrix.package)) && steps.verify-changed-files.outputs.files_changed != 'true' }}
uses: andymckay/labeler@3a4296e9dcdf9576b0456050db78cfd34853f260
uses: ./.github/actions/remove-label
with:
remove-labels: 'needs-go-generate-${{matrix.package}}'
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ needs.pr_metadata.outputs.issue_number }}
label: 'needs-go-generate-${{matrix.package}}'
16 changes: 6 additions & 10 deletions .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,16 @@ jobs:
yarn.lock
- name: Add Label
if: steps.verify-yarn-lock.outputs.files_changed == 'true'
uses: andymckay/labeler@3a4296e9dcdf9576b0456050db78cfd34853f260
if: ${{ steps.verify-yarn-lock.outputs.files_changed == 'true' && github.event_name != 'push' }}
uses: ./.github/actions/add-label
with:
add-labels: 'needs-yarn-install'
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ needs.issue_number.outputs.issue_number }}
label: 'needs-yarn-install'

- name: Remove Label
if: steps.verify-yarn-lock.outputs.files_changed != 'true'
uses: andymckay/labeler@3a4296e9dcdf9576b0456050db78cfd34853f260
if: ${{ steps.verify-yarn-lock.outputs.files_changed != 'true' && github.event_name != 'push' }}
uses: ./.github/actions/add-label
with:
remove-labels: 'needs-yarn-install'
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ needs.issue_number.outputs.issue_number }}
label: 'needs-yarn-install'


- name: Run tests # Run tests of all packages
Expand Down

0 comments on commit 8852be5

Please sign in to comment.