Role of GitHub Actions Workflow in CI/CD Setup
Steps to Create a GitHub Actions Workflow
Use of GitHub Actions Job
Github Action custom jobs
automates the process of building a Flutter Android APK
workflow automates both building your Flutter Android app and publishing the output
Build & Release Debug
Build & Release Laravel Vite React
Prompt to create yaml file for ci cd setup
Role of GitHub Actions Workflow in CI/CD Setup
GitHub Actions workflows are central to automating Continuous Integration (CI) and Continuous Deployment (CD) processes directly within a GitHub repository. Here’s how they function and their significance in a CI/CD pipeline:
Workflow as the Automation Unit
A GitHub Actions workflow is a YAML-defined automation that executes a series of steps, triggered by specific events like code pushes, pull requests, or scheduled times.
The workflow can be configured to build, test, package, release, or deploy a project, covering the entire CI/CD lifecycle.
Continuous Integration (CI)
CI workflows typically run on every code change (push, pull request), automatically building the code, running tests, and performing static analysis to ensure code quality and catch errors early.
Each workflow consists of jobs that run in isolated virtual environments, which can be specified by the developer (e.g., different operating systems or versions).
Steps within jobs execute tasks such as checking out code, installing dependencies, running linters, and executing test suites.
Continuous Deployment/Delivery (CD)
Workflows can be extended to include deployment steps, pushing artifacts or code to production or staging environments after successful CI checks.
Integration with deployment platforms (e.g., Deno Deploy, cloud providers) is achieved by adding deployment actions at the end of the workflow, ensuring only tested code is released.
Key Benefits
Automation
: Eliminates manual intervention by automating repetitive tasks like builds, tests, and deployments.
Consistency
: Ensures the same process is followed for every change, reducing human error and increasing reliability.
Visibility
: CI/CD status and logs are available in the GitHub interface, making it easy to track build and deployment health.
Customization
: Workflows are highly configurable, supporting parallel jobs, matrix builds (testing across multiple OS/versions), and conditional steps
Steps to Create a GitHub Actions Workflow
create GitHub Actions Workflow on Remote
Create the Workflow Directory and File
In your repository, create a directory named .github/workflows if it doesn't already exist.
craeate directory named .github/workflows automatically by click setup workflow yourself
step 1:first click action
step2 second click setup workflow yourself
Inside this directory, create a new YAML file for your workflow, such as ci.yml or actions-demo.yml. The file extension must be .yml or .yaml.
- Define the Workflow Structure in YAML
Open your new workflow file and start by specifying the workflow’s name (optional), trigger event(s), jobs, and steps. Here’s a basic template:
name: CI Workflow
on: [push] # Triggers the workflow on every push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run a sample script
run: echo "Hello, GitHub Actions!"
name: (Optional) The name of your workflow as it appears in the GitHub Actions tab.
on: Specifies the event(s) that trigger the workflow, such as push, pull_request, or a schedule.
jobs: Groups the jobs to run. Each job runs on a specified runner (e.g., ubuntu-latest).
steps: The individual tasks to perform, such as checking out code, installing dependencies, or running scripts.
- Commit and Push the Workflow File
Save and commit the workflow file to your repository.
Push the changes to GitHub. The workflow will automatically run if the trigger event (e.g., a push) occurs.
- View Workflow Runs and Results
Go to the "Actions" tab in your GitHub repository to see your workflow runs.
Click on a workflow run to view detailed logs and the status of each step.
create GitHub Actions Workflow in Local
Ensure Your Project Is Under GitHub Version Control
Make sure your project is already pushed to a GitHub repository. If not, you can initialize a Git repository in Visual Studio and publish it to GitHub.
- Open the Project in Visual Studio
Open your solution or project in Visual Studio.
If your repository already contains workflows, you’ll see a "GitHub Actions" node in Solution Explorer (Visual Studio 2022 v17.7+).
- Create the Workflow File Locally
In Solution Explorer, right-click your project or the repository root.
Navigate to the .github/workflows directory. If this directory does not exist, create it under your project root.
Add a new file with a .yml or .yaml extension, for example, ci.yml.
You can use Visual Studio’s built-in editor or any text editor to edit the YAML workflow file.
- Author the Workflow
Paste or write your workflow YAML. Here’s a basic example for a .NET project:
text
name: .NET Build and Test
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
Save the file in .github/workflows/.
- Commit and Push the Workflow File
Commit the new workflow YAML file to your local repository.
Push the changes to GitHub. This will trigger the workflow based on the events you specified (e.g., push to main).
- (Optional) Run and Test Workflows Locally
You can use the GitHub Local Actions extension for Visual Studio Code or the nektos/act CLI tool to run and test workflows locally before pushing.
This is especially useful for quick feedback without needing to push every change.
- Monitor Workflow Runs
In Visual Studio, you can double-click the YAML file under the GitHub Actions node to view details.
On GitHub, use the "Actions" tab to see workflow runs, logs, and results
Use of GitHub Actions Job
Run Unit Tests
Execute automated tests for your codebase (Node.js, Python, Java, etc.).
Build Docker Image
Build a Docker image from your repository and optionally push to Docker Hub or a registry.
Deploy to Cloud Provider
Deploy your application to AWS, Azure, GCP, or DigitalOcean.
Publish to Package Registry
Publish npm, PyPI, Maven, or RubyGems packages automatically on release.
Static Code Analysis
Run linters or static analysis tools (like ESLint, Flake8, SonarQube) for code quality.
Security Vulnerability Scan
Scan dependencies for vulnerabilities using tools like npm audit, snyk, or trivy.
Send Notifications
Send build status or deployment notifications to Slack, Microsoft Teams, or email.
Deploy to GitHub Pages
Build and deploy static sites or documentation to GitHub Pages.
Close Stale Issues/PRs
Automatically close or label issues and pull requests that have been inactive for a set period.
Matrix Testing
Run the same tests across multiple OSes or versions (e.g., Node 16, 18, 20; Ubuntu, Windows, Mac).
Run Scheduled Jobs (Cron)
Schedule jobs to run at specific times (e.g., nightly builds, backups, or reports).
Automated Code Formatting
Run Prettier, Black, or other formatters and optionally commit changes.
Sync Fork with Upstream
Automatically keep a forked repository up to date with the upstream source.
Generate and Deploy Documentation
Build API or code documentation and publish it (e.g., to Pages or S3).
Upload Build Artifacts
Save build outputs (binaries, logs, reports) as downloadable artifacts for later use.
Trigger External Workflows or APIs
Use curl or workflow dispatch to trigger jobs in other repos or external systems.
Run Infrastructure as Code
Execute Terraform, Ansible, or Pulumi scripts to manage cloud infrastructure.
Check Code Coverage
Run tests and upload coverage reports to Codecov or Coveralls.
Label or Assign Issues/PRs
Automatically add labels or assign reviewers based on content or file changes.
Automated Dependency Updates
Use bots (like Dependabot) to create PRs for outdated dependencies.
Continuous Integration (CI) for Node.js
Installs dependencies, runs tests, and builds your project on every pull request or push.
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm test
- run: npm run build
Continuous Deployment (CD) to Firebase
Automatically deploys your app to Firebase Hosting after a successful build.
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm install
- run: npm run build
- uses: w9jds/firebase-action@v13.0.2
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
Publish a Package to npm on Release
Publishes your JavaScript package to npm when you create a new GitHub Release.
jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm install
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Send Slack Notification on Build Failure
Notifies your team in Slack if a workflow fails.
jobs:
notify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
Build and Test a Java/Maven Project
Compiles and tests your Java project using Maven.
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '17'
- run: mvn clean install
Lint and Format Code
Runs a linter (like ESLint or Prettier) to enforce code style and catch errors.
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm install
- run: npm run lint
Build Docker Image and Push to Docker Hub
Builds a Docker image and pushes it to Docker Hub on every push to main.
jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- run: docker build -t ${{ secrets.DOCKER_USERNAME }}/my-app:latest .
- run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- run: docker push ${{ secrets.DOCKER_USERNAME }}/my-app:latest
Cache Dependencies to Speed Up Builds
Uses GitHub's cache action to store and restore dependencies, making builds faster.
jobs:
cache:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- run: npm install
Run Tests on Multiple OS and Node Versions (Matrix Build)
Tests your code on different operating systems and Node.js versions.
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: [16, 18, 20]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm test
Upload Build Artifacts
Stores build outputs (like binaries, logs, or reports) as downloadable artifacts.
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm install
- run: npm run build
- uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: ./dist
Automatically Label Pull Requests
Add labels to PRs based on their content or files changed.
jobs:
label:
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v5
- Close Stale Issues and PRs Automatically close issues and PRs that have been inactive for a certain period.
jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
days-before-stale: 30
days-before-close: 7
- Check for Security Vulnerabilities Run npm audit or similar tools to check for known vulnerabilities.
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm install
- run: npm audit --audit-level=high
- Send Email Notifications Send an email when a workflow completes.
jobs:
email:
runs-on: ubuntu-latest
steps:
- uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.example.com
server_port: 465
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.SMTP_PASSWORD }}
subject: Workflow finished
body: The workflow has completed!
to: you@example.com
from: github-actions@example.com
- Generate and Deploy Documentation to GitHub Pages Automatically build and publish documentation.
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm install
- run: npm run docs:build
- uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/.vuepress/dist
- Run Python Unit Tests Set up Python, install dependencies, and run tests.
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install -r requirements.txt
- run: pytest
- Check Code Coverage and Upload to Codecov Run tests and upload coverage reports.
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm install
- run: npm run test -- --coverage
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
- Sync Fork with Upstream Repository Keep your fork up to date with the original repository.
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: tgymnich/fork-sync@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
owner: upstream-owner
repo: upstream-repo
- Publish Python Package to PyPI Build and upload your Python package to PyPI on release.
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: python setup.py sdist bdist_wheel
- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- Trigger Another Workflow or Repository Use a workflow dispatch to trigger another workflow or repo.
jobs:
trigger:
runs-on: ubuntu-latest
steps:
- uses: benc-uk/workflow-dispatch@v1
with:
workflow: deploy.yml
repo: other-org/other-repo
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
Github Action custom jobs
Spell Check Documentation
Check all Markdown files for spelling errors on every pull request.
jobs:
spellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: rojopolis/spellcheck-github-actions@v0
Generate a Changelog on Release
Automatically generate a changelog file when a new release is published.
jobs:
changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: heinrichreimer/action-github-changelog-generator@v2.3
Auto-Assign Reviewers to Pull Requests
Assign specific reviewers to every new pull request.
jobs:
assign-reviewers:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: kentaro-m/auto-assign-action@v1.2.2
Run Lighthouse Audit on Deploy Preview
Test website performance with Lighthouse after deploying a preview.
jobs:
lighthouse:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: treosh/lighthouse-ci-action@v11
with:
urls: 'https://preview.example.com'
Sync Issues to Jira
Automatically create or update Jira issues from GitHub issues.
jobs:
sync-jira:
runs-on: ubuntu-latest
steps:
- uses: atlassian/gajira-create@v3
with:
project: MYPROJ
summary: ${{ github.event.issue.title }}
description: ${{ github.event.issue.body }}
env:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
- Auto-Merge Dependabot PRs Automatically merge pull requests created by Dependabot if tests pass.
jobs:
automerge:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pascalgn/automerge-action@v0.16.3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- Enforce Commit Message Convention Fail the build if commit messages don’t match a conventional format.
jobs:
commit-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: wagoid/commitlint-github-action@v5
- Run End-to-End Browser Tests Launches a browser and runs E2E tests using Cypress.
jobs:
e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cypress-io/github-action@v6
- Backup Database Nightly Every night, dump the database and upload the backup as an artifact.
jobs:
backup-db:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Dump DB
run: pg_dump -U postgres mydb > backup.sql
- uses: actions/upload-artifact@v4
with:
name: db-backup
path: backup.sql
Send Tweet on Release
Automatically tweet from a project account when a new release is published.
jobs:
tweet:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ethomson/send-tweet-action@v1
with:
status: "🎉 New release: ${{ github.event.release.tag_name }} is out!"
env:
TWITTER_CONSUMER_KEY: ${{ secrets.TWITTER_CONSUMER_KEY }}
TWITTER_CONSUMER_SECRET: ${{ secrets.TWITTER_CONSUMER_SECRET }}
TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }}
TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
automates the process of building a Flutter Android APK
name: "Build"
on:
pull_request:
branches: [main, master]
push:
branches: [main, master, develop]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
architecture: x64
- run: flutter pub get
- run: flutter build apk --release --split-per-abi
workflow automates both building your Flutter Android app and publishing the output
name: "Build & Release"
on:
pull_request:
branches: [main, master]
push:
branches: [main, master, develop]
jobs:
build:
name: Build & Release
runs-on: ubuntu-latest # You can use ubuntu-latest for Android-only
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
architecture: x64
- run: flutter pub get
- run: flutter build apk --release --split-per-abi
# Or, for Play Store, use:
# - run: flutter build appbundle --release
- name: Push to Releases
uses: ncipollo/release-action@v1
with:
artifacts: "build/app/outputs/apk/release/*"
tag: v1.0.${{ github.run_number }}
token: ${{ secrets.rakesh }}
Build & Release Debug
name: "Build & Release Debug"
on:
push:
branches: [main, master, develop]
permissions:
contents: write
jobs:
build:
name: Build & Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Debug step to check token existence
- name: Debug - Check Token Existence
run: |
echo "Token exists: ${{ secrets.rakesh != '' }}"
echo "Runner OS: ${{ runner.os }}"
echo "GitHub Reference: ${{ github.ref }}"
echo "Run Number: ${{ github.run_number }}"
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
architecture: x64
- run: flutter pub get
- run: flutter build apk --release --split-per-abi
# Debug step to verify APK files exist
- name: Debug - Check APK Files
run: |
echo "Listing APK files:"
find build/app/outputs/apk/release -type f -name "*.apk" | sort
echo "File count: $(find build/app/outputs/apk/release -type f -name "*.apk" | wc -l)"
echo "Directory structure:"
ls -la build/app/outputs/apk/release/
# Try a GitHub-based approach first with detailed GitHub token
- name: Create Release (GitHub CLI)
id: create_release_cli
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Attempting release creation with GitHub CLI"
gh release create v1.0.${{ github.run_number }} ./build/app/outputs/apk/release/*.apk \
--title "Release v1.0.${{ github.run_number }}" \
--notes "Release created by GitHub Actions"
continue-on-error: true
# Only run ncipollo action if GitHub CLI approach fails
- name: Push to Releases (Original)
if: steps.create_release_cli.outcome != 'success'
uses: ncipollo/release-action@v1
with:
artifacts: "build/app/outputs/apk/release/*"
tag: v1.0.${{ github.run_number }}
token: ${{ secrets.rakesh }}
name: "Release v1.0.${{ github.run_number }} (ncipollo)"
draft: false
prerelease: false
allowUpdates: true
replacesArtifacts: true
# Debug step to report final status
- name: Debug - Workflow Summary
run: |
echo "GitHub CLI release status: ${{ steps.create_release_cli.outcome }}"
echo "Workflow completed at: $(date)"
echo "Check the Releases page at: https://github.com/${{ github.repository }}/releases"
Build & Release Laravel Vite React
name: Build & Release Laravel Vite React
on:
push:
branches: [main, master, develop]
permissions:
contents: write
jobs:
build:
name: Build & Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Set up PHP environment (8.2)
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mbstring, bcmath, xml, curl, gd
ini-values: post_max_size=256M, upload_max_filesize=256M
coverage: none
# Install Composer dependencies
- name: Install Composer Dependencies
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
# Set up Node.js environment (22.x)
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.7.0'
cache: 'npm'
# Install npm dependencies
- name: Install npm dependencies
run: npm ci
# Build assets with Vite
- name: Build Vite Assets
run: npm run build
# Debug step to check build output
- name: Debug - List public build files
run: |
echo "Listing files in public/build directory:"
ls -la public/build
# Create a release with built assets (example)
- name: Create Release (GitHub CLI)
id: create_release_cli
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Attempting release creation with GitHub CLI"
gh release create v1.0.${{ github.run_number }} public/build/* \
--title "Release v1.0.${{ github.run_number }}" \
--notes "Release created by GitHub Actions"
continue-on-error: true
# Fallback release action if GitHub CLI fails
- name: Push to Releases (Original)
if: steps.create_release_cli.outcome != 'success'
uses: ncipollo/release-action@v1
with:
artifacts: "public/build/*"
tag: v1.0.${{ github.run_number }}
token: ${{ secrets.GITHUB_TOKEN }}
name: "Release v1.0.${{ github.run_number }} (ncipollo)"
draft: false
prerelease: false
allowUpdates: true
replacesArtifacts: true
# Debug step to report final status
- name: Debug - Workflow Summary
run: |
echo "GitHub CLI release status: ${{ steps.create_release_cli.outcome }}"
echo "Workflow completed at: $(date)"
echo "Check the Releases page at: https://github.com/${{ github.repository }}/releases"
Prompt to create yaml file for ci cd setup
openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)
modify my yaml file to build and relaese in github for ci cd setup of flutter mobile app accroding to above jdk version
PS C:\myworkspace\motoshare-web> php -version
PHP 8.2.12 (cli) (built: Oct 24 2023 21:15:15) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies
PS C:\myworkspace\motoshare-web> node -v
v22.7.0
PS C:\myworkspace\motoshare-web>
modify my yaml file to build and relaese in github for ci cd setup of laravel with vite react js frontend accroding to above php version and node or npm version
Top comments (0)