$30 off During Our Annual Pro Sale. View Details »

CSC309 Lecture 14

CSC309 Lecture 14

Software Engineering II
Continuous Integration
(202305)

Javier Gonzalez-Sanchez
PRO

February 13, 2023
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs
    CSC 309
    Software Engineering II
    Lecture 14:
    Continuous Integration
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    www.javiergs.com
    Building 14 -227
    Office Hours: By appointment

    View Slide

  2. jgs
    Previously …

    View Slide

  3. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 3
    Key Ideas CSC 309
    architecture
    design
    code
    unit testing
    integration
    testing
    verification
    verification
    quality measure

    View Slide

  4. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 4
    Code repositories
    Let's you an others work together on projects from anywhere.
    (version control and collaboration)
    Context

    View Slide

  5. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 5
    GitHub
    A code hosting platform (free for public projects)
    Tool

    View Slide

  6. jgs
    1. Continuous Integration

    View Slide

  7. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 7
    § 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

    View Slide

  8. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 8
    Continuous Integration (CI)
    https://www.devopsschool.com/blog/top-10-continuous-integration-tool/
    used in combination with
    automated tests
    use a build server to
    implement continuous
    compilation, running unit and
    integration tests, and even
    static analyses and profile
    performance.

    View Slide

  9. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 9
    § When?
    Several times a day – Grady Booch 1991
    Agile methods recommend continuous integration to discover software
    problems earlier (Ken Beck, 1998)
    Continuous Integration (CI)

    View Slide

  10. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 10
    § Which One?
    Money, Experience, Learning Curve
    Jenkins, Travis, and CircleCI have been popular options.
    Tools
    Build
    Test
    Report

    View Slide

  11. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 11
    § GitHub launched their own Continuous Integration(CI) and Deployment (CD)
    system called GitHub Actions.
    § You can implement CI directly inside the tool that store your code (2019).
    Tools

    View Slide

  12. jgs
    2. GitHub Actions

    View Slide

  13. jgs
    3. Set Up

    View Slide

  14. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 14
    GitHub

    View Slide

  15. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 15
    Maven
    A build automation tool used

    View Slide

  16. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 16

    pom.xml

    View Slide

  17. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 17
    src/test/java/*.java

    View Slide

  18. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 18
    GitHub Actions
    1
    2

    View Slide

  19. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 19
    § Actions are individual jobs that can be combined in a
    Workflow to create a complex pipeline.
    (Jobs such as build the code in your repository and run your tests)
    § A Workflow can be configured in YAML file and
    triggered to run on specific events
    (such as each time someone pushes code to the master branch).
    Workflow
    YAML file
    events
    jobs

    View Slide

  20. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 20
    .gitbub/workflows/maven.yml
    YAML file
    events
    jobs
    👆

    View Slide

  21. jgs
    4. Run

    View Slide

  22. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 22
    push

    View Slide

  23. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 23
    GitHub Actions
    1

    View Slide

  24. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 24
    GitHub Actions
    1
    2

    View Slide

  25. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 25
    GitHub Actions
    1

    View Slide

  26. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 26
    GitHub Actions

    View Slide

  27. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 27
    Email

    View Slide

  28. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 31

    View Slide

  29. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 32
    § 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

    View Slide

  30. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 33
    Office Hours
    Tuesday and Thursday 3 - 5 pm
    But an appointment required
    Sent me an email – [email protected]

    View Slide

  31. jgs

    View Slide

  32. jgs
    CSC 309
    Software Engineering II
    Lab 14:
    Continuous Integration
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    www.javiergs.com
    Building 14 -227
    Office Hours: By appointment

    View Slide

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

    View Slide

  34. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 37
    3. 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

    View Slide

  35. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 38
    4. 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.

    View Slide

  36. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 39
    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
    );
    }
    }

    View Slide

  37. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 40
    5. Junit Dependency
    • Either your IDE takes car of the
    dependency or goes and add it
    manually as follows
    (this is Junit 5)


    org.junit.jupiter
    junit-jupiter
    5.8.2
    test


    View Slide

  38. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 41
    5. Junit Dependency
    • And let us ask Maven to build the
    application also.



    org.apache.maven.plugins
    maven-surefire-plugin
    2.22.2



    View Slide

  39. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 42
    5. Connect your IDE and your GitHub Repository
    • VCS / Share your project on GitHub

    View Slide

  40. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 43
    5. Do NOT share everything
    • VCS / Share your project on GitHub

    View Slide

  41. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 44
    1. GitHub
    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)

    View Slide

  42. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 45
    1. GitHub Actions
    1. Go to Actions.
    2. Select Java with Maven
    3. A maven.yml file will appear
    4. Click Start commit

    View Slide

  43. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 46
    1. 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.

    View Slide

  44. jgs
    Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 | 47
    Let’s Work

    View Slide

  45. 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.

    View Slide