GitHub Actions can be used to do something whenever something happens in one of your GitHub repositories. If you are not familiar with GitHub Actions, check out my article Getting Started with GitHub Actions.
Let's say you have the following GitHub Action, to copy foo.jpg in your GitHub repo to the /tmp directory on one of your Amazon Web Services (AWS) EC2 instance.
name: GitHub Action
run-name: ${{ github.workflow }} run by ${{ github.actor }}
on:
push:
branches:
- main
jobs:
github-action-job:
runs-on: ubuntu-latest
steps:
- name: Checking out the repository code
uses: actions/checkout@v4
- name: copy foo.jpg to /tmp
uses: appleboy/scp-action@master
with:
host: ec2-10-11-12-13.compute-1.amazonaws.com
username: ec2-user
password: ${{ secrets.PASSWORD }}
port: 22
source: "foo.jpg"
target: "/tmp"
Notice this run has on push branches main so that a commit is made to the main branch in the repo, the GitHub Action will be run to copy foo.jpg to /tmp. Of course, this isn't the most real world scenario - just trying to keep the concept simple here.
on:
push:
branches:
- main
This is kind of a hassle for proof of concept testing and debugging, because you would have to make a commit in the main branch of the repo to get this workflow to trigger. Let's add workflow_dispatch.
on:
push:
branches:
- main
workflow_dispatch:
With workflow_display, now when we select our workflow, there should be an option to Run workflow, allowing us to manully run the GitHub Action without having to make a commit in the repo. Nice!
Did you find this article helpful?
If so, consider buying me a coffee over at