Master GitHub Actions with hands-on labs and exercises. Learn how to automate workflows, run tests, deploy applications, and more using GitHub's powerful automation platform. This repository has everything you need to get started with continuous integration and continuous deployment.
In this lab, you will:
Ensure the following directory structure exists in your repository:
.github/
└── actions/
└── print-message-and-time-composite-action/
├── action.yml
action.yml
)Create the action.yml
file in the .github/actions/print-message-and-time-composite-action
directory:
name: "Print Message and Time"
description: "Prints a custom message and the current date/time"
author: "Your Name"
inputs:
message:
description: "The message to print"
required: true
default: "Hello, GitHub Actions!"
outputs:
timestamp:
description: "The current date and time"
runs:
using: "composite"
steps:
# Step 1: Print the input message
- name: Print the message
run: echo "Message: $"
# Step 2: Capture and output the current time
- name: Get current timestamp
id: current_time
run: echo "timestamp=$(date)" >> $GITHUB_ENV
# Step 3: Set the output from the timestamp
- name: Set action output
run: echo "timestamp=$"
shell: bash
message
with a default value of "Hello, GitHub Actions!"
.timestamp
).$GITHUB_ENV
to capture the timestamp for output.test-composite-action.yml
Create a workflow file in .github/workflows/test-composite-action.yml
to use the composite action:
name: Test Composite Action
on:
push:
branches:
- main
workflow_dispatch:
jobs:
test-composite-action:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository
- name: Checkout code
uses: actions/checkout@v4
# Step 2: Use the composite action
- name: Run the custom composite action
id: composite-action
uses: ./github/actions/print-message-and-time-composite-action
with:
message: "Hello from Composite Action!"
# Step 3: Access and display the output of the composite action
- name: Print the timestamp
run: echo "The timestamp is: $"
main
branch.Hello from Composite Action!
).message
) with a default option.$GITHUB_ENV
to capture and expose data across steps.In this lab, you: