Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 19 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,31 @@
# github-actions-playground
This repository is used as a playground to learn and mess with github actions.
# Github Actions Playground

## Notes
In this repository you can find templates and examples of some github actions workflows that I use in my own projects.
They are mainly focused around Typescript and React Native projects, because that's what I work with most of the time.

A basic workflow is configured as follows:
Feel free to copy them and use them in your own projects.

```yaml
## Contributing

name: CI
Contributions are welcome! If you have a workflow that you think is useful and you want to share it, feel free to open a
pull request.

on: [push]
## Workflows

jobs:
build:
name: Build
runs-on: ubuntu-latest
### Release with [release-it](https://github.com/release-it/release-it)

steps:
- name: SayHi
run: echo "Hello, ${{ github.actor }}"
This workflow is triggered manually and can bypass the ruleset that blocks any push to the main branch. It does it by
using a Github App that has been added to the bypass list in the branch protection rules.
Take a look at the [release-it-setup](./docs/release-it-setup.md) document to see how to set it up and an alternative
approach to the bypass procedure.

```
### Pass artifacts to next jobs

Each job runs in a fresh instance of the virtual environment, this means that we need to checkout the branch and install
the dependencies in each job;
This workflow shows how to pass artifacts from one job to another.
Take a look at the [pass-artifacts-to-next-job](./docs/pass-artifacts-to-next-jobs.md) document to see how to set it up.

Continuos Integration (CI): is the practice of automating the integration of code changes from multiple contributors
into a single software project. The CI process is comprised of automatic tools that assert the new code’s correctness
before integration. This means that you can set up github actions to run tests, linters, etc. on each push to the
repository or on a pull request.
## Useful links

- [Github Actions Documentation](https://docs.github.com/en/actions)

Continuous Deployment (CD): is the practice of automating the deployment of code changes to a production environment.
This means that you can set up github actions to deploy your code to a server, a cloud provider, etc. once you are
ready to release a new version of your software.

By default, github actions have got the GITHUB_TOKEN secret, which is a token that allows the action to interact with the
github API. This token is automatically created by github and is available to all actions. You can use this token to
create issues, pull requests, etc. from your actions.
If you want to push to the repository tho, you need to update the permissions of the token and you can do it right in
the worflow file using the `permissions` key.
63 changes: 63 additions & 0 deletions docs/pass-artifacts-to-next-jobs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Pass artifacts to next jobs

When you have a workflow with multiple jobs and you need to pass artifacts (products) from one job to the next ones,
you can use the `needs` keyword and a couple of actions from the GitHub Marketplace.

The `needs` keyword allows you sequence the jobs in a workflow. You can specify that a job can only run after another
job has completed successfully. This is required when you need to pass artifacts from one job to another.

To actually pass the artificats, you can use the `upload-artifact` and `download-artifact` actions from the GitHub
Marketplace. The `upload-artifact` action allows you to upload a file or directory as an artifact. The `download-artifact`
action allows you to download an artifact from a previous job.

Take a look at the following example:

```yaml

name: pass-artifacts-to-next-jobs

on: workflow_dispatch

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup

- name: Build
run: yarn build

- name: Upload Build Artifact
uses: actions/upload-artifact@v4
with:
name: build-artifact
path: build

run-build:
name: Run build
runs-on: ubuntu-latest
needs: build

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup

- name: Download Build Artifact
uses: actions/download-artifact@v4
with:
name: build-artifact

- name: Run
# This assumes that your build artifacts is an index.js
run: node index.js

```
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "github-actions-playground",
"description": "Playground to learn and save all github-actions template I use on my open source projects.",
"version": "0.0.0",
"packageManager": "yarn@4.6.0",
"scripts": {
"release": "release-it --dry-run",
"release": "release-it",
"build": "tsc",
"lint": "eslint ./src"
},
Expand Down