Top 50 GitHub Actions Interview Question and Answers

By Shyam Mohan
Top 50 GitHub Actions  Interview Question  and Answers
  1. What is GitHub Actions?

    • GitHub Actions is a CI/CD platform that enables automation directly within GitHub repositories for building, testing, and deploying code.
  2. How do workflows work in GitHub Actions?

    • Workflows are automated processes defined in YAML files under .github/workflows and are triggered by specific events, such as push or pull_request.
  3. What are jobs in GitHub Actions?

    • Jobs are individual tasks that run within workflows. Each job can include multiple steps and can run in parallel or sequentially.
  4. Explain steps in GitHub Actions.

    • Steps are the individual tasks executed in a job. They can be custom shell commands or actions.
  5. What are runners in GitHub Actions?

    • Runners are servers that execute workflows. GitHub provides hosted runners, or you can use self-hosted runners for custom environments.
  6. What’s the difference between GitHub-hosted and self-hosted runners?

    • GitHub-hosted runners are managed by GitHub and provide common tools. Self-hosted runners are managed by users for custom configurations.
  7. How do you define a workflow trigger in GitHub Actions?

    • Workflow triggers are defined using the on keyword, specifying events like push, pull_request, or schedule.
  8. What are reusable workflows in GitHub Actions?

    • Reusable workflows allow common tasks to be centralized in one workflow file and invoked in multiple repositories.
  9. What are artifacts in GitHub Actions?

    • Artifacts are files generated by workflows (e.g., build files) that can be saved and shared across jobs or with users.
  10. How do you manage secrets in GitHub Actions?

    • Secrets are stored in GitHub repository settings and accessed in workflows using $ syntax.
  11. How can you run a job only on specific branches?

    • Specify branches under the on condition, e.g., on: push: branches: [main, dev].
  12. What is a matrix strategy in GitHub Actions?

    • Matrix strategy runs a job multiple times with different configurations (e.g., OS, Node.js versions).
  13. Explain how caching works in GitHub Actions.

    • GitHub Actions supports caching dependencies to speed up workflow execution using the actions/cache action.
  14. What is needs in GitHub Actions?

    • needs is used to define job dependencies, ensuring jobs run sequentially when necessary.
  15. How do you add conditional logic to GitHub Actions workflows?

    • Use if statements to define conditions, such as if: success() or if: always().
  16. What is the purpose of continue-on-error?

    • continue-on-error: true allows a job to proceed even if a step fails.
  17. What is a composite action?

    • A composite action bundles multiple steps in one action, making it reusable.
  18. How do you pass environment variables across jobs?

    • Use env for global or job-level variables or pass them as outputs between jobs.
  19. How do you debug workflows in GitHub Actions?

    • Use ::debug:: commands, review logs, or set up ACTIONS_RUNNER_DEBUG in secrets for verbose logging.
  20. How do you run scheduled workflows?

    • Use on: schedule with a cron syntax (e.g., cron: '0 0 * * 1' for weekly triggers).
  21. How do you reuse workflows across repositories?

    • Use reusable workflows by referencing them in other repositories with the uses syntax.
  22. How do you handle secrets in workflows safely?

    • GitHub Actions masks secrets automatically and restricts them from appearing in logs.
  23. What is the purpose of job.container?

    • job.container allows running jobs inside a Docker container for isolated environments.
  24. What is jobs.<job_id>.outputs?

    • Outputs are values that can be set in a job and accessed by dependent jobs.
  25. Explain the purpose of the env keyword.

    • env defines environment variables for steps, jobs, or workflows.
  26. How can you use a Docker image in GitHub Actions?

    • Define container: image: <docker-image> in the job or use Docker commands in steps.
  27. How do you specify a particular runner version?

    • Choose an OS version (e.g., runs-on: ubuntu-latest or runs-on: windows-2019).
  28. What’s the purpose of jobs.<job_id>.timeout-minutes?

    • This sets a timeout for the job, after which it’s automatically canceled.
  29. What is a service container?

    • Service containers are additional containers run alongside jobs, useful for databases or message queues.
  30. What’s the difference betweenactions/checkout@v2 and actions/checkout@v3?

    • Each major version may introduce performance improvements and bug fixes; v3 includes enhancements over v2.
  31. What are custom actions?

    • Custom actions are user-defined tasks created in JavaScript or Docker that can be reused across workflows.
  32. How do you use GitHub Actions with multiple repositories?

    • Use checkout with repository names or trigger workflows across repos using repository_dispatch.
  33. What is concurrency in GitHub Actions?

    • Concurrency controls simultaneous runs of workflows, allowing them to cancel previous runs if needed.
  34. How can you prevent secrets from leaking?

    • Mask secrets in logs, avoid set-output with secrets, and use secrets safely in workflows.
  35. How do you handle GitHub Actions permissions?

    • Set granular permissions for actions in the repository settings or permissions keyword in workflows.
  36. What is the purpose of GITHUB_TOKEN?

    • GITHUB_TOKEN is an auto-generated token providing access to the repo for secure API interactions.
  37. What is jobs.<job_id>.strategy.fail-fast?

    • It stops all jobs in a matrix if any job fails, reducing resource use.
  38. How do you manage workflow concurrency?

    • Use concurrency to limit simultaneous runs or cancel redundant runs with cancel-in-progress.
  39. What are required status checks in GitHub Actions?

    • These are checks that must pass before merging, typically set in branch protection rules.
  40. Explain the purpose of jobs.<job_id>.defaults.

    • defaults provides default run settings for steps in a job.
  41. How do you handle errors in GitHub Actions?

    • Use if: failure() for error handling, or add continue-on-error for steps that shouldn’t block progress.
  42. What are the best practices for securing workflows?

    • Avoid exposing secrets, validate inputs, and use reusable actions from trusted sources.
  43. How can you optimize GitHub Actions for performance?

    • Use caching, parallel jobs, matrix builds, and reusable workflows.
  44. How do you troubleshoot failed workflows?

    • Check logs, enable debug logging, and use the ::debug:: command.
  45. What’s the purpose of jobs.<job_id>.env?

    • env at the job level sets environment variables available to all steps in that job.
  46. How do you create a GitHub Action using JavaScript?

    • Create an action.yml file, define inputs, and use JavaScript to build the action logic.
  47. What’s the role of jobs.<job_id>.if?

    • if allows conditional job execution based on specific criteria.
  48. What is on.workflow_call?

    • on.workflow_call triggers a reusable workflow, allowing it to be called from other workflows.
  49. How can you share artifacts across jobs?

    • Use upload-artifact to save files in one job and download-artifact to access them in another.
  50. What are the benefits of GitHub Actions over other CI/CD tools?

    • GitHub Actions provides native GitHub integration, reusable workflows, strong community support, and flexible automation.

Enjoyed this article? Share it.

Shares
linkedin sharing button Share
facebook sharing button Share
twitter sharing button Post
whatsapp sharing button Share
sharethis sharing button Share

Subscribe to our LinkedIn Newsletter

Stay updated with the latest in Container Native DevOps & Cloud FinOps

Subscribe


Ready to Streamline Your Kubernetes Performance and Cost?

Experience seamless Kubernetes Auto tuning with RazorOps.

Schedule a Free Meeting Now.