{"id":32963,"date":"2024-11-01T09:12:47","date_gmt":"2024-11-01T09:12:47","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32963"},"modified":"2024-11-01T11:29:34","modified_gmt":"2024-11-01T11:29:34","slug":"spring-boot-backend-development-course-12-2-using-github-actions","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32963\/","title":{"rendered":"Spring Boot Backend Development Course, 12.2 Using GitHub Actions"},"content":{"rendered":"<p><body><\/p>\n<p>Hello! In this tutorial, we will learn about GitHub Actions, a method to automate CI\/CD (Continuous Integration\/Continuous Deployment) for Spring Boot applications. GitHub Actions is a CI\/CD tool that is directly integrated into GitHub repositories, making it very useful for automating software development workflows. In this article, we will cover the basic concepts of GitHub Actions, how to set it up, and how to apply it to a Spring Boot project.<\/p>\n<h2>1. What is GitHub Actions?<\/h2>\n<p>GitHub Actions is a CI\/CD platform provided by GitHub that allows you to automatically perform various tasks based on events in your project repository. When code is pushed or a Pull Request (PR) is created, it can automatically handle tasks such as running tests, creating builds, and deploying by executing a specific workflow.<\/p>\n<h3>1.1 Features of GitHub Actions<\/h3>\n<ul>\n<li><strong>Flexibility:<\/strong> You can easily create custom workflows and actions, leveraging numerous open-source actions.<\/li>\n<li><strong>Version Control:<\/strong> Each action supports versioning, allowing you to maintain a consistent environment by using specific versions of actions.<\/li>\n<li><strong>Security:<\/strong> It offers various security tools and authentication features to ensure safety in production environments.<\/li>\n<\/ul>\n<h2>2. Getting Started<\/h2>\n<p>First, to use GitHub Actions, you need to create a repository on GitHub. If you already have a repository, you can simply add actions to that repository.<\/p>\n<h3>2.1 Create a GitHub Account<\/h3>\n<p>If you do not have a GitHub account, <a href=\"https:\/\/github.com\/join\" target=\"_blank\" rel=\"noopener\">sign up here<\/a>.<\/p>\n<h3>2.2 Create a New Repository<\/h3>\n<p>After logging in to GitHub, click the &#8216;+&#8217; button in the top-right corner and select &#8216;New repository&#8217;. Set the repository name, description, visibility, etc., and click &#8216;Create repository&#8217; to create a new repository.<\/p>\n<h2>3. Create a Simple Spring Boot Application<\/h2>\n<p>Now let&#8217;s develop a Spring Boot application. We will use Spring Initializr to generate the basic structure.<\/p>\n<h3>3.1 Using Spring Initializr<\/h3>\n<p>Visit the following link to set up your project: <a href=\"https:\/\/start.spring.io\/\" target=\"_blank\" rel=\"noopener\">Spring Initializr<\/a>. Choose the necessary dependencies and click the &#8216;Generate&#8217; button to download a zip file. Now unzip this file and open it in your IDE.<\/p>\n<h3>3.2 Writing Basic Code<\/h3>\n<p>To create a simple REST API, write the following code.<\/p>\n<pre><code>@RestController\npublic class HelloController {\n    @GetMapping(\"\/hello\")\n    public String hello() {\n        return \"Hello, Spring Boot!\";\n    }\n}<\/code><\/pre>\n<h2>4. Setting Up GitHub Actions<\/h2>\n<p>Next, let&#8217;s set up GitHub Actions to add automated builds and test executions.<\/p>\n<h3>4.1 Create .github\/workflows Directory<\/h3>\n<p>Create a <code>.github\/workflows<\/code> directory in the project root. This is where the action definition files will be placed.<\/p>\n<h3>4.2 Create Workflow File<\/h3>\n<p>The workflow file is written in YAML format. Write the following code in a file named <code>java_ci.yml<\/code>.<\/p>\n<pre><code>name: Java CI\n\non:\n  push:\n    branches: [ main ]\n  pull_request:\n    branches: [ main ]\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n\n    steps:\n    - name: Check out code\n      uses: actions\/checkout@v2\n\n    - name: Set up JDK 11\n      uses: actions\/setup-java@v1\n      with:\n        java-version: '11'\n        \n    - name: Build with Gradle\n      run: .\/gradlew build<\/code><\/pre>\n<h3>4.3 Explanation of the Workflow<\/h3>\n<p>In the above code, the <strong>on<\/strong> keywords followed by <strong>push<\/strong> and <strong>pull_request<\/strong> define that the workflow will execute when those events occur. The <strong>jobs<\/strong> section can define multiple tasks, each running in a specific environment. The <strong>steps<\/strong> section defines necessary scripts to be executed in each step.<\/p>\n<h2>5. Adding Tests<\/h2>\n<p>Now, let&#8217;s add test code to the Spring Boot application. We will add a simple unit test as follows.<\/p>\n<pre><code>@SpringBootTest\npublic class HelloControllerTest {\n\n    @Autowired\n    private MockMvc mockMvc;\n\n    @Test\n    public void helloShouldReturnMessage() throws Exception {\n        mockMvc.perform(get(\"\/hello\"))\n               .andExpect(status().isOk())\n               .andExpect(content().string(\"Hello, Spring Boot!\"));\n    }\n}<\/code><\/pre>\n<h3>5.1 Updating the Test Workflow<\/h3>\n<p>Add the command to execute the tests in the YAML file created above.<\/p>\n<pre><code>- name: Run tests\n      run: .\/gradlew test<\/code><\/pre>\n<h2>6. Commit and Push<\/h2>\n<p>Commit all changes and push to the remote repository.<\/p>\n<pre><code>git add .\ngit commit -m \"Add GitHub Actions workflow\"\ngit push origin main<\/code><\/pre>\n<h3>6.1 Check Workflow Execution<\/h3>\n<p>Go to the &#8216;Actions&#8217; tab of your GitHub repository to check if the workflow has executed successfully. If the build completes successfully, all settings have been configured correctly.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this tutorial, we learned how to easily set up CI\/CD using GitHub Actions in a Spring Boot application. Automated workflows can keep the development and deployment process efficient and consistent. Continuously leverage GitHub Actions to improve the quality of your projects!<\/p>\n<h2>Additional Resources<\/h2>\n<ul>\n<li><a href=\"https:\/\/docs.github.com\/en\/actions\" target=\"_blank\" rel=\"noopener\">GitHub Actions Documentation<\/a><\/li>\n<li><a href=\"https:\/\/spring.io\/projects\/spring-boot\" target=\"_blank\" rel=\"noopener\">Spring Boot Project<\/a><\/li>\n<li><a href=\"https:\/\/gradle.org\/\" target=\"_blank\" rel=\"noopener\">Gradle<\/a><\/li>\n<\/ul>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello! In this tutorial, we will learn about GitHub Actions, a method to automate CI\/CD (Continuous Integration\/Continuous Deployment) for Spring Boot applications. GitHub Actions is a CI\/CD tool that is directly integrated into GitHub repositories, making it very useful for automating software development workflows. In this article, we will cover the basic concepts of GitHub &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32963\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Spring Boot Backend Development Course, 12.2 Using GitHub Actions&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[131],"tags":[],"class_list":["post-32963","post","type-post","status-publish","format-standard","hentry","category-spring-boot-backend-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring Boot Backend Development Course, 12.2 Using GitHub Actions - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/32963\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Boot Backend Development Course, 12.2 Using GitHub Actions - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello! In this tutorial, we will learn about GitHub Actions, a method to automate CI\/CD (Continuous Integration\/Continuous Deployment) for Spring Boot applications. GitHub Actions is a CI\/CD tool that is directly integrated into GitHub repositories, making it very useful for automating software development workflows. In this article, we will cover the basic concepts of GitHub &hellip; \ub354 \ubcf4\uae30 &quot;Spring Boot Backend Development Course, 12.2 Using GitHub Actions&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32963\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:12:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:29:34+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32963\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32963\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Spring Boot Backend Development Course, 12.2 Using GitHub Actions\",\"datePublished\":\"2024-11-01T09:12:47+00:00\",\"dateModified\":\"2024-11-01T11:29:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32963\/\"},\"wordCount\":591,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Spring Boot backend development\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32963\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32963\/\",\"name\":\"Spring Boot Backend Development Course, 12.2 Using GitHub Actions - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:12:47+00:00\",\"dateModified\":\"2024-11-01T11:29:34+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32963\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32963\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32963\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring Boot Backend Development Course, 12.2 Using GitHub Actions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Boot Backend Development Course, 12.2 Using GitHub Actions - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/32963\/","og_locale":"ko_KR","og_type":"article","og_title":"Spring Boot Backend Development Course, 12.2 Using GitHub Actions - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello! In this tutorial, we will learn about GitHub Actions, a method to automate CI\/CD (Continuous Integration\/Continuous Deployment) for Spring Boot applications. GitHub Actions is a CI\/CD tool that is directly integrated into GitHub repositories, making it very useful for automating software development workflows. In this article, we will cover the basic concepts of GitHub &hellip; \ub354 \ubcf4\uae30 \"Spring Boot Backend Development Course, 12.2 Using GitHub Actions\"","og_url":"https:\/\/atmokpo.com\/w\/32963\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:12:47+00:00","article_modified_time":"2024-11-01T11:29:34+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32963\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32963\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Spring Boot Backend Development Course, 12.2 Using GitHub Actions","datePublished":"2024-11-01T09:12:47+00:00","dateModified":"2024-11-01T11:29:34+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32963\/"},"wordCount":591,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Spring Boot backend development"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32963\/","url":"https:\/\/atmokpo.com\/w\/32963\/","name":"Spring Boot Backend Development Course, 12.2 Using GitHub Actions - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:12:47+00:00","dateModified":"2024-11-01T11:29:34+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32963\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32963\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32963\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Spring Boot Backend Development Course, 12.2 Using GitHub Actions"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=32963"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32963\/revisions"}],"predecessor-version":[{"id":32964,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32963\/revisions\/32964"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}