Re: [PATCH v2 1/2] CI: limit GitHub Actions to designated branches
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- May 6, 2020, 15:09 UTC
- Message-ID
- <nycvar.QRO.7.76.6.2005061623520.56@tvgsbejvaqbjf.bet>
- In-Reply-To
- <xmqqlfm69il6.fsf@gitster.c.googlers.com>
Hi,
On Tue, 5 May 2020, Junio C Hamano wrote:
Show 31 quoted lines
> Jeff King <peff@peff.net> 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