GitHub Actions (Basic)

beginner
18 min

GitHub Actions (Basic)

Welcome to our comprehensive GitHub Actions tutorial! In this guide, we'll explore the world of GitHub Actions, a powerful automation tool that's perfect for beginners and intermediates. Let's get started!

šŸŽÆ Understanding GitHub Actions

GitHub Actions automate your software workflows. They are event-driven, meaning they run in response to specific events, such as pushing code, opening a pull request, or releasing a new version.

šŸ“ Note:

Why GitHub Actions? They save time by automating repetitive tasks, making your development process more efficient and less error-prone.

šŸ’” Setting Up a Workflow

A GitHub Actions workflow is defined in a .yml file in the .github/workflows directory of your repository. Here's a simple example:

yml
name: Hello World on: [push, pull_request] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up JDK 8 uses: actions/setup-java@v2 with: java-version: 8 - name: Hello World run: | java -version echo "Hello, World!"

šŸ’” Pro Tip: The name field provides a human-readable title for your workflow. The on field specifies when the workflow should run. The jobs section contains one or more jobs, each with a name and a series of steps.

šŸ“ Note:

In the above example, the workflow runs on Ubuntu, checks out your code, sets up JDK 8, and prints "Hello, World!"

šŸ’” Practical Example

Let's create a workflow that builds and tests a simple Node.js application.

yml
name: Node.js CI on: [push, pull_request] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Use Node.js uses: actions/setup-node@v2 with: node-version: 14 - name: Install Dependencies run: npm install - name: Run Tests run: npm test

šŸ’” Pro Tip: In this example, the workflow checks out your code, sets up Node.js version 14, installs dependencies, and runs tests using the npm test command.

šŸŽÆ Quiz Time

Quick Quiz
Question 1 of 1

What triggers a GitHub Action workflow?

We hope this tutorial has given you a solid introduction to GitHub Actions. In the next lesson, we'll dive deeper into more advanced concepts and examples. Happy coding! šŸš€