diff --git a/.github/actions/add-label/README.md b/.github/actions/add-label/README.md new file mode 100644 index 0000000000..b497acbcba --- /dev/null +++ b/.github/actions/add-label/README.md @@ -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}} +``` diff --git a/.github/actions/add-label/action.yml b/.github/actions/add-label/action.yml new file mode 100644 index 0000000000..d9503ff11e --- /dev/null +++ b/.github/actions/add-label/action.yml @@ -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 }}'] + }) diff --git a/.github/actions/remove-label/README.md b/.github/actions/remove-label/README.md new file mode 100644 index 0000000000..b84b4fb322 --- /dev/null +++ b/.github/actions/remove-label/README.md @@ -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}} +``` diff --git a/.github/actions/remove-label/action.yml b/.github/actions/remove-label/action.yml new file mode 100644 index 0000000000..9b5ec0c653 --- /dev/null +++ b/.github/actions/remove-label/action.yml @@ -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 }}'] + }) diff --git a/.github/actions/setup-nodejs/action.yml b/.github/actions/setup-nodejs/action.yml index bbf20ef3c3..f7bce16077 100644 --- a/.github/actions/setup-nodejs/action.yml +++ b/.github/actions/setup-nodejs/action.yml @@ -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 }}' diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 5252a0f98d..971032cfa7 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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)" @@ -380,7 +379,7 @@ 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 @@ -388,7 +387,7 @@ jobs: 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: @@ -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: @@ -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}}' diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml index 1441c3045c..e633e5f962 100644 --- a/.github/workflows/packages.yml +++ b/.github/workflows/packages.yml @@ -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