Yes, we can learn github without coding. We can focus on understanding version control concepts, repository management, collaboration features, and using github for project management.
Key takeaways
GitHub actions allows us to create workflows to automate tasks directly within the github repositories.
Workflows are defined in YAML files located in the
.github/workflows
directory of your repository.We can set specific events (like
push
orpull_request
) that trigger the workflow, enabling automation based on changes to your codebase.Workflows consist of jobs and each job contains steps that execute commands or actions, allowing us to automate tasks such as building, testing, or deploying our application.
We can choose different runner environments (e.g.,
ubuntu-latest
,windows-latest
) to match the requirements of the project, ensuring compatibility and optimal performance.
GitHub provides a powerful automation tool named github Actions that has the capability to run workflows directly within our custom github repositories. It allows us to create workflows to automate tasks directly within the github repositories. These workflows are most commonly used for automation purposes, such as testing, continuous integration, and continuous deployment (CI/CD).
GitHub Actions are defined in YAML files stored in the .github/workflows
directory of the repository. Each workflow consists of a series of steps that are executed in response to specific events, known as triggers. The common triggers we encounter will be through push and pull requests, or scheduled events. As the trigger occurs, the associated workflow is executed and the steps will be performed.
We will need a github account, a personal access token, and an empty repository. Details about acquiring a While generating a personal access token token, select the repo and the workflow scopes.
Workflows live in the .github/workflows
directory. For the purposes of our example, we're going to create a file called first.yaml
which will hold our first workflow. The contents of the first.yaml
file will include specific steps that the workflow will execute. These steps could involve checking out code, running scripts, or performing various automated tasks.
The contents of this file are shown below:
name: our-first-workflow on: push jobs: echo: runs-on: ubuntu-latest steps: - name: echo step run: echo 'hello world!'
Let's understand our first workflow in detail:
name
: specifies the name of the workflow
on
: This section defines the event that will trigger the workflow. In this case, the workflow is set to run on any push
event to the repository. This means that whenever we push changes to any branch in the repository, this workflow will be executed.
jobs
: This section defines a job named echo
. Jobs are a collection of steps that run in the same environment. We can have multiple jobs defined here.
runs-on: ubuntu-latest
: This specifies the environment where the job will execute. ubuntu-latest
means that the job will run on the latest version of the Ubuntu operating system provided by github Actions.
steps
: This section lists the individual tasks that the job will execute.
name
: This step is named echo step
.
run
: The run
keyword allows us to specify shell commands that will be executed. In this case, it uses the echo
command, which prints the provided string to the output log of the workflow.
Run the following commands in the above terminal to trigger the workflow:
cd usercodegit config --global user.name github_usergit config --global user.email github_emailgit init && git remote add origin github_repogit remote -vgit add .git commit -am 'Our First Workflow'git branch maingit remote set-url origin https://<username>:<personal-access-token>@github.com/<username>/<repository>.gitgit push origin main
You will have to fill the commands with your own values, as follows:
github_email
: Our github account's email.
github_user
: Our github account's username.
github_repo
: The link to our empty github repository.
After running these commands, redirect to the github repository and click on the Actions tab. Here we should see that our workflow has executed:
This workflow is a straightforward example of how to create a basic github action. It triggers on every push to the repository and runs a single job that echoes "hello world!" to the console.
GitHub Actions provide an effective way to automate workflows within the repositories.
By defining workflows in YAML, we can streamline our development process and implement CI/CD practices. This simple example serves as a foundation for more complex workflows, enabling us to integrate testing, deployment, and other automation tasks into your projects.
Haven’t found what you were looking for? Contact Us
Free Resources