Re: [PATCH v2 1/2] CI: limit GitHub Actions to designated branches

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Tue, 5 May 2020, Junio C Hamano wrote:

> Jeff King <peff@xxxxxxxx> writes:
>
> >  jobs:
> > +  check-ci:
> > +      runs-on: ubuntu-latest
> > +      outputs:
> > +        enabled: ${{ steps.check-ref.outputs.enabled }}
> > +      steps:
> > +        - uses: actions/checkout@v2
> > +          continue-on-error: true
> > +          with:
> > +            ref: refs/ci/config
> > +        - id: check-ref
> > +          name: check whether CI is enabled for ref
> > +          run: |
> > +            enabled=yes
> > +            if test -e ref-whitelist &&
> > +               ! grep '^${{ github.ref }}$' ref-whitelist
> > +            then
> > +              enabled=no
> > +            fi
> > +            echo "::set-output name=enabled::$enabled"
> > +
> >    windows-build:
> > +    needs: check-ci
> > +    if: needs.check-ci.outputs.enabled == 'yes'
> >      runs-on: windows-latest
> >      steps:
> >      - uses: actions/checkout@v1
>
> Oh, quite nice.  Simple and clean.

The idea is indeed very neat. I think we can do a bit better with resource
usage by not even bothering to check this branch out. Something along
those lines (sorry, I really would love to have the time to test this...):

      - id: check-ref
        name: check whether CI is enabled for ref
        uses: actions/github-script@0.9.0
        with:
          script: |
            const req = {
              owner: context.repo.owner,
              repo: context.repo.repo,
              ref: "ci/config"
            };

            try {
              req.tree_sha = (await github.git.getRef(req)).data.object.sha;
              (await github.git.getTree(req))
              .tree.filter(e => e.path == 'ref-whitelist').map(e => {
                req.file_sha = e.sha;
              });
              const list = Buffer.from((await github.git.getBlob(req)).data.content, 'base64').toString('UTF-8');
              core.setOutput('enabled', `\n${list}`.indexOf(`\n${{github.ref}}\n`) < 0 ? 'no' : 'yes');
            } catch (e) {
              core.setOutput('enabled', 'yes');
            }

Ciao,
Dscho




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux