├── .github └── workflows │ └── main.yml ├── LICENSE ├── README.md └── dates.txt /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # https://help.github.com/en/articles/workflow-syntax-for-github-actions#name 2 | name: Main 3 | 4 | # https://help.github.com/en/articles/workflow-syntax-for-github-actions#on 5 | on: repository_dispatch 6 | 7 | # https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobs 8 | jobs: 9 | 10 | # https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_id 11 | first_job: 12 | 13 | # https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idruns-on 14 | runs-on: ubuntu-latest 15 | 16 | # https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idsteps 17 | steps: 18 | 19 | # https://help.github.com/en/articles/virtual-environments-for-github-actions#default-environment-variables 20 | # https://github.com/actions/checkout 21 | - uses: actions/checkout@v1 22 | 23 | # https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepsid 24 | - name: Update dates.txt with new date 25 | 26 | # https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepsenv 27 | env: 28 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 29 | 30 | # https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepsrun 31 | run: | 32 | 33 | # ensure we're on the `master` branch. 34 | git checkout master 35 | 36 | # create or update `dates.txt` 37 | touch dates.txt 38 | 39 | # append the current datetime to the end of `dates.txt` 40 | echo `date` >> dates.txt 41 | 42 | # reveal what `dates.txt` looks like in the logs 43 | cat dates.txt 44 | 45 | # Git: set identity 46 | git config --global user.name "github-actions" 47 | git config --global user.email "github-actions@users.noreply.github.com" 48 | 49 | # Git: set remote 50 | # https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#http-based-git-access-by-an-installation 51 | git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" 52 | 53 | # Git: add, commit, and push changes 54 | git add dates.txt 55 | git commit -m "github-actions: update dates.txt" 56 | GIT_TRACE=1 git push --verbose 57 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 francisfuzz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # on-dispatch-trigger-workflow 2 | 3 | This repository is an example of triggering a GitHub Actions workflow via the [repository dispatch event](https://developer.github.com/v3/repos/#creating-a-repository-dispatch-event). 4 | 5 | The repository dispatch event will trigger a new workflow execution that creates or updates your repo's `dates.txt` with a new date. 6 | 7 | ## Usage 8 | 9 | * Fork the repo to your account 10 | * Ensure `curl` is installed. (https://curl.haxx.se/) 11 | * Then, Open the command line interface application of your choice and make this `curl` request, replacing `$TOKEN` with a [personal access token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) and `:owner` and `:repo` with the appropriate values 12 | 13 | 14 | ```shell 15 | curl -v -H "Accept: application/vnd.github.everest-preview+json" \ 16 | -H "Authorization: token $TOKEN" \ 17 | https://api.github.com/repos/:owner/:repo/dispatches \ 18 | -d '{"event_type":"update-dates-file"}' 19 | ``` 20 | -------------------------------------------------------------------------------- /dates.txt: -------------------------------------------------------------------------------- 1 | Wed Aug 28 19:57:38 UTC 2019 2 | Wed Aug 28 20:02:41 UTC 2019 3 | Wed Aug 28 20:04:35 UTC 2019 4 | Wed Aug 28 20:07:07 UTC 2019 5 | Wed Aug 28 20:11:10 UTC 2019 6 | Wed Aug 28 20:19:56 UTC 2019 7 | Tue Sep 10 18:38:55 UTC 2019 8 | Tue Oct 1 05:12:51 UTC 2019 9 | Thu Oct 24 01:06:45 UTC 2019 10 | Sat Nov 2 00:30:29 UTC 2019 11 | --------------------------------------------------------------------------------