Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSC309 Lecture 11

CSC309 Lecture 11

Software Engineering II
Continuous Deployment
(202405)

Javier Gonzalez-Sanchez

February 05, 2023
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs CSC 309 Software Engineering II Lecture 11: Continuous Deployment

    Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.com Building 14 -227 Office Hours: By appointment
  2. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    4 § What? The practice of automating the integration of code changes from multiple contributors into a single software project. Continuous Integration (CI) https://www.pagerduty.com
  3. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    6 1. name: Java CI with Maven 2. on: 3. push: 4. branches: ["main"] 5. pull_request: 6. branches: ["main"] 7. jobs: 8. build: 9. runs-on: ubuntu-latest 10. steps: 11. - uses: actions/checkout@v4 12. - name: STEP 01 Set up JDK 20 13. uses: actions/setup-java@v4 14. with: 15. java-version: '20' 16. distribution: 'temurin' 17. cache: maven maven.yml
  4. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    7 19. - name: STEP 02. Build with Maven 20. run: mvn -B clean package --file pom.xml 21. - name: STEP 03. Run tests 22. run: mvn test 23. maven.yml
  5. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    9 19. - name: STEP 02. Build with Maven 20. run: mvn -B clean package --file pom.xml 21. - name: STEP 03. Run tests 22. run: mvn test 23. 24. - name: STEP 04. Deploy 25. run: mkdir staging && cp target/*.jar staging 26. 27. - name: Step 05. Just for Fun an LS 28. run: ls -al target 29. - name: Step 06. Set Executable Permissions 30. run: chmod +x target/testing-2024-1.0-SNAPSHOT.jar 31. - name: Step 07. Upload Artifact 32. uses: actions/upload-artifact@v4 33. with: 34. name: javiergs-app 35. path: target/testing-2024-1.0-SNAPSHOT.jar maven.yml
  6. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    21 1. name: Add JAR to GitHub Release 2. on: 3. release: 4. types: [created] 5. jobs: 6. upload-jar: 7. runs-on: ubuntu-latest 8. steps: 9. - uses: actions/checkout@v4 10. 11. - name: Step 01. Set up JDK 20 12. uses: actions/setup-java@v4 13. with: 14. java-version: '20' 15. distribution: 'temurin' 16. cache: maven maven.yml
  7. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    22 19. - name: Step 02. Build with Maven 20. run: mvn clean package 21. 22. - name: Step 03. Deploy 23. run: mkdir staging && cp target/*.jar staging 24. - name: Step 04. Set Executable Permissions 25. run: chmod +x target/testing-2024-1.0-SNAPSHOT.jar 26. - name: Step 05. Upload JAR to GitHub Release 27. uses: actions/upload-release-asset@v1 28. env: 29. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 30. with: 31. upload_url: ${{ github.event.release.upload_url }} 32. asset_path: "target/testing-2024-1.0-SNAPSHOT.jar" 33. asset_name: "testing-2024-1.0-SNAPSHOT.jar" 34. asset_content_type: "application/java-archive" maven-publish.yml
  8. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    26 § Chapter 25 Configuration Management - Continuous Integration § Understanding GitHub Actions https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions § Maven https://maven.apache.org/guides/introduction/introduction-to-the-pom.html References
  9. jgs

  10. jgs CSC 309 Software Engineering II Lab 11: Continuous Integration

    Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.com Building 14 -227 Office Hours: By appointment
  11. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    30 1. IDE • Use your IDE • Create a new project and either choice as build system Maven or add Maven as you did before.
  12. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    31 2. Code • Add this class: public class Main { public static void main(String args[]) { hypothenuse(10, 20); } public static double hypothenuse(double a, double b) { return Math.sqrt(Math.pow(a,2) + Math.pow(b,2)); } } • It should be in src/main/java folder. • Check your Maven
  13. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    32 3. Test Case • Create a test case. You can do that by selecting your class name, right-clicking, selecting generate…/Test… • Select the method to be tested and click OK.
  14. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    33 4. Junit Dependency • Either your IDE takes car of the dependency or goes and add it manually as follows (this is Junit 5) <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.8.2</version> <scope>test</scope> </dependency> </dependencies>
  15. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    34 5. Run Your Test Case • You can test something like this: import org.junit.jupiter.api.Assertions; class MainTest { @Test void hypothenuse() { Assertions.assertEquals( Main.hypothenuse(10,20), 22.360679774997898 ); } }
  16. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    35 6. Build • And let us ask Maven to build the application also. <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> </plugin> </plugins> </build>
  17. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    36 7. Connect your IDE and your GitHub Repository • VCS / Share your project on GitHub
  18. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    37 8. Do NOT share everything • VCS / Share your project on GitHub
  19. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    38 9. GitHub readme.md 1. Go To GitHub and add a README.md file 2. Edit the README file and add your names (only team members present) 3. Add me as a collaborator (javiergs)
  20. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    39 10. GitHub Actions 1. Go to Actions. 2. Select Java with Maven 3. A maven.yml file will appear 4. Click Commit
  21. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    40 11. GitHub Actions Permissions 1. If the Build fails, then go to Settings/Actions/General and provide Read and Write permissions to Workflow 2. Review your Java versions 8. 11, 15, 19 etc. It is better if they match.
  22. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    41 12. GitHub Actions <<Optional>> 1. Delete the <<optional>> part from the YML file – the last 3 lines
  23. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    43 12. GitHub Actions <<Optional>> 1. Make the test case for hypothenuse() to run
  24. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    44 12. GitHub Actions <<Optional>> 1. Deploy a JAR file as an Artifact inside of Workflow results 2. Look to your POM.xml for this <groupId>javiergs</groupId> <artifactId>testing-2024</artifactId> <version>1.0-SNAPSHOT</version>
  25. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    45 12. GitHub Actions <<Optional>> 1. Deploy a JAR file as an Artifact inside of Workflow results 2. Look to your POM.xml for this <groupId>javiergs</groupId> <artifactId>testing-2024</artifactId> <version>1.0-SNAPSHOT</version>
  26. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    46 12. GitHub Actions <<Optional>> 1. Create a new release for the hypotenuse assignment (version 1)
  27. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    47 12. GitHub Actions <<Optional>> 1. Add a workflow to upload a JAR to GitHub release for every new release (create a version N to test)
  28. jgs CSC 309 Software Engineering II Javier Gonzalez-Sanchez, Ph.D. [email protected]

    Winter 2023 Copyright. These slides can only be used as study material for the class CSC308 at Cal Poly. They cannot be distributed or used for another purpose.