home / tils / til

Menu
  • GraphQL API

til: github-actions_different-steps-on-a-schedule.md

This data as json

path topic title url body html shot created created_utc updated updated_utc shot_hash slug
github-actions_different-steps-on-a-schedule.md github-actions Running different steps on a schedule https://github.com/simonw/til/blob/main/github-actions/different-steps-on-a-schedule.md Say you have a workflow that runs hourly, but once a day you want the workflow to run slightly differently - without duplicating the entire workflow. Thanks to @BrightRan, here's [the solution](https://github.community/t5/GitHub-Actions/Schedule-once-an-hour-but-do-something-different-once-a-day/m-p/54382/highlight/true#M9168). Use the following pattern in an `if:` condition for a step: github.event_name == 'schedule' && github.event.schedule == '20 17 * * *' Longer example: ```yaml name: Fetch updated data and deploy on: push: schedule: - cron: '5,35 * * * *' - cron: '20 17 * * *' jobs: build_and_deploy: runs-on: ubuntu-latest steps: # ... - name: Download existing .db files if: |- !(github.event_name == 'schedule' && github.event.schedule == '20 17 * * *') env: DATASETTE_TOKEN: ${{ secrets.DATASETTE_TOKEN }} run: |- datasette-clone https://biglocal.datasettes.com/ dbs -v --token=$DATASETTE_TOKEN ``` I used this [here](https://github.com/simonw/big-local-datasette/blob/35e1acd4d9859d3af2feb29d0744ce1550e5faec/.github/workflows/deploy.yml), see [#11](https://github.com/simonw/big-local-datasette/issues/11). <p>Say you have a workflow that runs hourly, but once a day you want the workflow to run slightly differently - without duplicating the entire workflow.</p> <p>Thanks to @BrightRan, here's <a href="https://github.community/t5/GitHub-Actions/Schedule-once-an-hour-but-do-something-different-once-a-day/m-p/54382/highlight/true#M9168" rel="nofollow">the solution</a>. Use the following pattern in an <code>if:</code> condition for a step:</p> <pre><code>github.event_name == 'schedule' &amp;&amp; github.event.schedule == '20 17 * * *' </code></pre> <p>Longer example:</p> <div class="highlight highlight-source-yaml"><pre><span class="pl-ent">name</span>: <span class="pl-s">Fetch updated data and deploy</span> <span class="pl-ent">on</span>: <span class="pl-ent">push</span>: <span class="pl-ent">schedule</span>: - <span class="pl-ent">cron</span>: <span class="pl-s"><span class="pl-pds">'</span>5,35 * * * *<span class="pl-pds">'</span></span> - <span class="pl-ent">cron</span>: <span class="pl-s"><span class="pl-pds">'</span>20 17 * * *<span class="pl-pds">'</span></span> <span class="pl-ent">jobs</span>: <span class="pl-ent">build_and_deploy</span>: <span class="pl-ent">runs-on</span>: <span class="pl-s">ubuntu-latest</span> <span class="pl-ent">steps</span>: <span class="pl-c"><span class="pl-c">#</span> ...</span> - <span class="pl-ent">name</span>: <span class="pl-s">Download existing .db files</span> <span class="pl-ent">if</span>: <span class="pl-s">|-</span> <span class="pl-s"> !(github.event_name == 'schedule' &amp;&amp; github.event.schedule == '20 17 * * *')</span> <span class="pl-s"></span> <span class="pl-ent">env</span>: <span class="pl-ent">DATASETTE_TOKEN</span>: <span class="pl-s">${{ secrets.DATASETTE_TOKEN }}</span> <span class="pl-ent">run</span>: <span class="pl-s">|-</span> <span class="pl-s"> datasette-clone https://biglocal.datasettes.com/ dbs -v --token=$DATASETTE_TOKEN</span></pre></div> <p>I used this <a href="https://github.com/simonw/big-local-datasette/blob/35e1acd4d9859d3af2feb29d0744ce1550e5faec/.github/workflows/deploy.yml">here</a>, see <a href="https://github.com/simonw/big-local-datasette/issues/11">#11</a>.</p> <Binary: 50,020 bytes> 2020-04-20T07:39:39-07:00 2020-04-20T14:39:39+00:00 2020-04-20T09:24:01-07:00 2020-04-20T16:24:01+00:00 cc627abd8d10103171280dad5925be05 different-steps-on-a-schedule
Powered by Datasette · How this site works · Code of conduct