Skip to content

netserf/github-actions-fun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

github-actions-fun

This is a collection of GitHub Actions examples along with notes and references.

To limit the number of GitHub Actions minutes consumed, I've included a simple try_workflow.sh script that copies only one workflow file to the .github/workflow directory for execution and clears out any old workflow files.

1. Shell Commands with run:

./try_workflow.sh workflows/01_hello.yml
  • Status: Actions Status
  • Workflow: 01_hello.yml
  • Reference: jobs.<job_id>.steps[*].run
  • A simple workflow that demonstrates the run: statement to execute shell commands
  • Example runs in bash, python, and powershell using both ubuntu and windows

2. Executing Actions with uses:

./try_workflow.sh workflows/02_actions.yml

3. Serializing dependent jobs with needs:

./try_workflow.sh workflows/03_needs.yml
  • Status: Actions Status
  • Workflow: 03_needs.yml
  • References:
  • A workflow that demonstrates the needs: statement to serialize dependent jobs
  • Dependent jobs can be stated as a string or an array of strings
  • This example also illustrates marking a step with an id: attribute. These step id's can be used to reference different step contexts during execution

4. Checkout your GitHub repository

./try_workflow.sh workflows/04_checkout.yml
  • Status: Actions Status
  • Workflow: 04_checkout.yml
  • References:
  • An action that checks-out your repository into $GITHUB_WORKSPACE, so your workflow can access it
  • Once of many ready-made GitHub Actions to simplify your workflow

5. Trigger filters

./try_workflow.sh workflows/05_trigger_filters.yml
  • Status: Actions Status
  • Workflow: 05_trigger_filters.yml
  • References:
  • An example that shows how to filter the GHA triggers so only a subset of events will trigger the workflow
  • In this case the pull requests are filtered down to subset of events that are listed in the types: array

6. Trigger workflow on-demand

./try_workflow.sh workflows/06_on_demand_trigger.yml
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token <TOKEN>" \
<https://api.github.com/repos/OWNER/REPO/dispatches> \
-d '{"event_type":"on-demand-test","client_payload":{"unit":false,"integration":true}}'
  • Note that the event_type in the POST request must match one of the types: strings set in the repository_dispatch trigger

7. Scheduled triggers

./try_workflow.sh workflows/07_scheduled_trigger.yml

8. Environment Variables

./try_workflow.sh workflows/08_env_vars.yml
  • Status: Actions Status
  • Workflow: 08_env_vars.yml
  • References:
  • An example that shows how to use environment variables in a workflow
  • Environment variables can be set at the workflow level, the job level, or at the step level

9. Secrets

./try_workflow.sh workflows/09_secrets.yml
  • Status: Actions Status
  • Workflow: 09_secrets.yml
  • References:
  • An example that shows how to load secrets configured in your repository into your workflow

10. GitHub Tokens

./try_workflow.sh workflows/10_github_tokens.yml

11. Decrypt GPG-encrypted files

./try_workflow.sh workflows/11_decrypt_gpg.yml
  • Status: Actions Status
  • Workflow: 11_github_tokens.yml
  • References:
  • An example of how you can unencrypt a GPG-encrypted file in your workflow
  • This is using a simple symmetric cipher to perform the encryption
  • The my_secret_json.gpg file was encrypted using a passphrase to protect the secret. The following command performs the encryption:
gpg --symmetric --cipher-algo AES256 my_secret.json
  • The GPG_PASSPHRASE is configured in the repository's secrets so that it may be used in the workflow to unecrypt the file

12. Contexts

./try_workflow.sh workflows/12_contexts.yml
  • Status: Actions Status
  • Workflow: 12_contexts.yml
  • References:
  • An example workflow showing various GHA contexts
  • Contexts provide access to information about workflow runs, runner environments, jobs, and steps. Each context is an object that contains properties, which can be strings or other objects.

13. Functions

./try_workflow.sh workflows/13_functions.yml
  • Status: Actions Status
  • Workflow: 13_functions.yml
  • References:
  • An example workflow showing some of the GHA functions available
  • The number of functions is limited, so you consider other tooling if you need more functionality

14. Conditional Steps

./try_workflow.sh workflows/14_conditionals.yml

15. Matrix Strategy

./try_workflow.sh workflows/15_matrix_strategy.yml
  • Status: Actions Status
  • Workflow: 15_matrix_strategy.yml
  • References:
  • An example workflow showing how a matrix strategy can define a single job that automatically creates multiple jobs based on the matrix values
  • Very useful when you need to run test code against multiple versions and/or operating systems

16. Containers

./try_workflow.sh workflows/16_containers.yml

17. Multiple Containers

./try_workflow.sh workflows/17_multi_containers.yml
  • Status: Actions Status
  • Workflow: 17_multi_containers.yml
  • References:
  • An example workflow showing how to run a GHA job with a set of container-based services
  • An option to consider when testing a job that requires a backend service (e.g. API + database)

18. Customize Containers

./try_workflow.sh workflows/18_customize_containers.yml

19. Override Entrypoint

./try_workflow.sh workflows/19_override_entrypoint.yml

20. Message Slack

./try_workflow.sh workflows/20_message_slack.yml

21. Upload Artifact

./try_workflow.sh workflows/21_upload_artifact.yml
  • Status: Actions Status
  • Workflow: 21_upload_artifact.yml
  • References:
  • Upload Artifact
  • Download Artifact
  • An example showing how you can upload artifacts from your workflow to share data between jobs and store data once a workflow is complete.
  • Note that the uploaded artifact is available for 90 days and it can be found in the Actions tab, at the bottom of the workflow's summary page.

22. Auto Merge

./try_workflow.sh workflows/22_auto_merge.yml
  • Status: Actions Status
  • Workflow: 22_auto_merge.yml
  • References:
  • Auto Approve
  • Merge PR
  • An example showing how you can auto-approve and auto-merge a PR using GHA
  • Note that this will only work if the PR is opened by github.actor netserf.

Attributions

About

Example GitHub Actions workflows

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages