diff --git a/.github/workflows/run-app.yaml b/.github/workflows/run-app.yaml new file mode 100644 index 00000000..6ec58bc2 --- /dev/null +++ b/.github/workflows/run-app.yaml @@ -0,0 +1,10 @@ +name: 'Basic Action' + +on: [push] + +jobs: + check-bats-version: + runs-on: ubuntu-latest + steps: + - name: Basic Action + run: echo "Hello, World!" \ No newline at end of file diff --git a/Console/Console.csproj b/Console/Console.csproj index 26c0ed8b..939964bd 100644 --- a/Console/Console.csproj +++ b/Console/Console.csproj @@ -8,9 +8,12 @@ Exe TravisCI TravisCI - v4.5.2 + v4.8 512 true + + + AnyCPU @@ -32,8 +35,19 @@ 4 + + ..\packages\Microsoft.Build.Framework.17.1.0\lib\net472\Microsoft.Build.Framework.dll + + + ..\packages\Microsoft.VisualStudio.Setup.Configuration.Interop.3.0.4492\lib\net35\Microsoft.VisualStudio.Setup.Configuration.Interop.dll + True + + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + @@ -47,6 +61,14 @@ + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/Console/Program.cs b/Console/Program.cs index b3fcdf6a..9be02228 100644 --- a/Console/Program.cs +++ b/Console/Program.cs @@ -1,6 +1,6 @@ using System; -namespace TravisCILab +namespace GithubActionsLab { public class Program { diff --git a/Console/packages.config b/Console/packages.config new file mode 100644 index 00000000..a2084678 --- /dev/null +++ b/Console/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/TravisCI.sln b/GithubActions.sln similarity index 95% rename from TravisCI.sln rename to GithubActions.sln index c3edf276..a5fcf876 100644 --- a/TravisCI.sln +++ b/GithubActions.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2036 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32319.34 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console", "Console\Console.csproj", "{C5964EEF-DA27-4C98-B4D0-7F27767FE870}" EndProject diff --git a/LICENSE b/LICENSE index 01017ba8..436f9e8b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License -Copyright (c) 2018 Daric Teske +Copyright (c) 2018 Daric Teske for portions pertaining to the original Travis CI tutorial +Copyright (c) 2022 Katherine Gerot for portions pertaining to Github Actions modification Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 48bd629b..6a17b113 100644 --- a/README.md +++ b/README.md @@ -1,110 +1,146 @@ -[![Build Status](https://travis-ci.org/dteske25/TravisCI.svg?branch=master)](https://travis-ci.org/dteske25/TravisCI) +[![Run App](https://github.com/kgerot/GithubActions/actions/workflows/run-app.yaml/badge.svg)](https://github.com/kgerot/GithubActions/actions/workflows/run-app.yaml) + +# Do not submit a pull request to `kgerot/GithubActions` or `dteske/TraviCI`. Not following this instruction can ruin the lab for others, so pay attention. + +I receive around 60 pull requests every semester and have to manually delete each request and action run. Your actions will automatically fail if you open a pull request + +# Github Actions Lab + +Because Travis CI is no longer free, we are going to look at how Github Actions can provide continuous integration on a sample project. -# Travis CI Lab -We are going to be setting up continuous integration today on a sample project. Continuous integration can be used to perfom checks on written code, making sure that unit tests always pass or that formatting is followed, and that when changes are made, they don't break other areas of the code. -Unfortunately, to set up Travis CI on a private project, you have to pay for it, so you will have to make the repository public. Fork and clone the repo to your computer to get started. ## Run the Console App Just as a sanity check, make sure that everything is working before you begin. Try out the console app, see if you can break it and where the weaknesses in the code are. Try manually running the tests. -## Set up Travis CI to build the Console App -- Go to [travis-ci.org](http://travis-ci.org), and sign-in with your GitHub credentials. -- Accept the GitHub access permissions confirmation. -- Go to your profile page and enable this repository. -- Click the gear icon, and make sure the settings are as follows: +## Set up Github Actions to build the Console App -![travis-ci config](./img/travis-ci-config.png) +First, let's explore the Action UI on Github. Go to the Actions Tab and look at any running jobs. +Currently, there should be one job that has run successfully. -Add a `.travis.yml` file to the root folder for your project. This is your Travis config file. -> We're following the information from [this](https://docs.travis-ci.com/user/languages/csharp/) guide to set up our project. +![Actions Tab](./img/actions-tab.PNG) -Put the following in your Travis config: +If you open that job, you'll see we've programmed the action to just echo `Hello, World!`. If yo ucannot find a job, that's okay. Sometimes Github will not run an action immediately upon forking. -``` -language: csharp -solution: TravisCI.sln -branches: - only: - - master -install: - - nuget restore TravisCI.sln -script: - - msbuild /p:Configuration=Release TravisCI.sln +We want our action to build our project. To do this, navigate to the file `.github/workflows/run-app.yaml`. +This is where we have define a workflow that runs a process called `Basic Action` that echos `Hello, World!`. It runs on the latest Ubuntu OS and runs everytime you push. + +Replace the contents of the file with the code below + +```yaml +name: 'Run App FullName' + +on: [push, pull_request] + +jobs: + check-bats-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-dotnet@v1 + with: + dotnet-version: '5.0.301' + - uses: nuget/setup-nuget@v1 + - name: Nuget Restore + run: nuget restore GithubActions.sln + - name: Install dependencies + run: dotnet restore GithubActions.sln + - name: Build + run: msbuild /p:Configuration=Release GithubActions.sln ``` +- Replace FullName on the first line with your name for grading. - Commit and push these changes to master -- Open travis-ci.org and see if your build is running. -- A running build will look like the following in the left drawer: +- Open the Actions and see if your build is running (should be under the name of your commit). + +## Build Status Badge -![travis running](./img/travis-running.png) +Right now the build status badge at the top of this Readme is for the repo `kgerot/GithubActions` and we want it to be *your* repository. -You can follow along with the build log by clicking the gray circle in the upper-right of the build log: +To change this, go to your last build in Actions and open it. Click the three dots on the right side of the screen and click Create status badge. -![follow button](./img/follow-button.png) +Here, you can copy the markdown and replace the badge at the top of this Readme on the Github website or in VS. -You also might have noticed that the "build passing" badge at the top of the readme is also right here (though it might not say passing right now). To get your own link, just click that badge, and from the dropdown, select the link as markdown. It will look something similar to `[![Build Status](https://travis-ci.org/username/TravisCI.svg?branch=master)](https://travis-ci.org/username/TravisCI)`. It's really nice to have that in your readme file, so that you always know the build status of your master branch. +![Inside Job](./img/inner-test.PNG) + +![Badge Markdown](./img/badge-markdown.PNG) ## Implement the Power method -Once Travis CI is up and running, it should rebuild every time you push a change, or open a pull request. Let's test this out. +Once Github Actions is up and running, it should rebuild every time you push a change, or open a pull request. Let's test this out. - Implement the `Power` method found in `Program.cs`. - Commit and push the change to a different branch. -- Open a pull request. -- Verify that Travis CI started building your pull request. - -Travis CI is pretty well integrated into GitHub. I've got examples here showing the build statuses on the pull requests: +- Open a pull request **to your repository's main branch** -![pr overview](./img/pr-overview.png) -![pr detailed](./img/pr-detailed.png) +### Do not submit a pull request to `kgerot/GithubActions` or `dteske/TraviCI`. Not following this instruction can ruin the lab for others. +If you accidentally submit a pull request to the master branch of `kgerot/GithubActions`, please invite kgerot as a reviewer on the request so I can close it and properly fix the repository. -Once the build completes, merge your pull request with master. Verify Travis CI started building master again. - -## Set up Travis CI to run Unit Tests -To run the tests after every change, we'll have to modify the Travis config slightly. -Adjust the `script` section to be the following. +## Set up Github Actions to run Unit Tests +To run the tests after every change, we'll have to modify the .yaml slightly. Add the follwing code to the steps section: +```yaml + - name: Run Unit Tests + run: mono ./packages/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./Tests/bin/Release/Tests.dll ``` -script: - - msbuild /p:Configuration=Release TravisCI.sln - - mono ./packages/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./Tests/bin/Release/Tests.dll + +Your .yaml file should look like this now: +```yaml +name: 'Run App' + +on: [push, pull_request] + +jobs: + check-bats-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-dotnet@v1 + with: + dotnet-version: '5.0.301' + - uses: nuget/setup-nuget@v1 + - name: Nuget Restore + run: nuget restore GithubActions.sln + - name: Install dependencies + run: dotnet restore GithubActions.sln + - name: Build + run: msbuild /p:Configuration=Release GithubActions.sln + - name: Run Unit Tests + run: mono ./packages/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./Tests/bin/Release/Tests.dll ``` -This is the NUnit test runner, and will allow Travis CI to run the tests on the server from the command line. +This is the NUnit test runner, and will allow GithubActions to run the tests on the server from the command line. Commit and push this change to master. -Open Travis and make sure the build completes. +Open Actions and make sure the build completes. If you've done this correctly, the following should appear at the bottom of your build log: -![nunit-tests](./img/nunit-tests.png) +![nunit-tests](./img/passing-unit-tests.PNG) + +(once you have finished, use the same output to show all your unit tests) ## Implement the other unit tests Follow the same format as the addition unit tests, and implement tests for the rest of the operations defined in `Program.cs`. - Run the tests locally, and intentionally make one fail. - Commit and push the changes to a different branch. -- Open a new pull request. +- Open a new pull request **to your own master branch, not `kgerot/GithubActions` or `dteske25/TravisCI`**. -Travis CI will detect the pull request, and build it. Since we have a test failing, it should detect that. A failed build will look like the following; +Github Actions will detect the pull request, and build it. Since we have a test failing, it should detect that. A failed build will look like the following; -![failed build](./img/failed-build.png) +![failed build](./img/failed-job.PNG) And in GitHub it will look like: -![pr overview failed](./img/pr-overview-failed.png) -![pr detailed failed](./img/pr-detailed-failed.png) +![pr overview failed](./img/failed-pull.PNG) - Push a change on the same branch to fix the test. - See if the build completes successfully. In GitHub, that will look like the following: -![pr overview passed](./img/pr-overview-passed.png) -![pr detailed passed](./img/pr-detailed-passed.png) +![pr overview passed](./img/passed-pull.PNG) If everything passes, feel free to merge. You are now using CI. - -This is a pretty simple setup for Travis CI. There's a lot of customization that can be done, so check out https://docs.travis-ci.com/ if you're curious about how it could be used. This is a free service, so if you have a public side project, I'd encourage you to set up Travis CI on it. Even if you don't really need to use it, it's great practice. diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 09bfce34..995b5561 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -10,10 +10,11 @@ Properties Tests Tests - v4.5.2 + v4.8 512 + true @@ -33,11 +34,22 @@ 4 + + ..\packages\Microsoft.Build.Framework.17.1.0\lib\net472\Microsoft.Build.Framework.dll + + + ..\packages\Microsoft.VisualStudio.Setup.Configuration.Interop.3.0.4492\lib\net35\Microsoft.VisualStudio.Setup.Configuration.Interop.dll + True + ..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + @@ -64,5 +76,7 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + \ No newline at end of file diff --git a/Tests/UnitTests.cs b/Tests/UnitTests.cs index 84cde036..5d5f6f41 100644 --- a/Tests/UnitTests.cs +++ b/Tests/UnitTests.cs @@ -1,7 +1,7 @@ using System; using NUnit.Framework; -namespace TravisCILab +namespace GithubActionsLab { [TestFixture] public class Math diff --git a/Tests/packages.config b/Tests/packages.config index a04faee1..3a5f236a 100644 --- a/Tests/packages.config +++ b/Tests/packages.config @@ -1,6 +1,9 @@  + + + \ No newline at end of file diff --git a/img/actions-tab.PNG b/img/actions-tab.PNG new file mode 100644 index 00000000..8367e2ae Binary files /dev/null and b/img/actions-tab.PNG differ diff --git a/img/badge-markdown.PNG b/img/badge-markdown.PNG new file mode 100644 index 00000000..fc0c9525 Binary files /dev/null and b/img/badge-markdown.PNG differ diff --git a/img/failed-build.png b/img/failed-build.png deleted file mode 100644 index b2562765..00000000 Binary files a/img/failed-build.png and /dev/null differ diff --git a/img/failed-job.PNG b/img/failed-job.PNG new file mode 100644 index 00000000..c3264fb0 Binary files /dev/null and b/img/failed-job.PNG differ diff --git a/img/failed-pull.PNG b/img/failed-pull.PNG new file mode 100644 index 00000000..345fb74c Binary files /dev/null and b/img/failed-pull.PNG differ diff --git a/img/follow-button.png b/img/follow-button.png deleted file mode 100644 index 14d96de0..00000000 Binary files a/img/follow-button.png and /dev/null differ diff --git a/img/inner-test.PNG b/img/inner-test.PNG new file mode 100644 index 00000000..b3f80a57 Binary files /dev/null and b/img/inner-test.PNG differ diff --git a/img/mono-build.png b/img/mono-build.png deleted file mode 100644 index 5e8ca9da..00000000 Binary files a/img/mono-build.png and /dev/null differ diff --git a/img/nunit-tests.png b/img/nunit-tests.png deleted file mode 100644 index 91d7f49a..00000000 Binary files a/img/nunit-tests.png and /dev/null differ diff --git a/img/passed-pull.PNG b/img/passed-pull.PNG new file mode 100644 index 00000000..e9153a22 Binary files /dev/null and b/img/passed-pull.PNG differ diff --git a/img/passing-unit-tests.PNG b/img/passing-unit-tests.PNG new file mode 100644 index 00000000..63d88673 Binary files /dev/null and b/img/passing-unit-tests.PNG differ diff --git a/img/pr-detailed-failed.png b/img/pr-detailed-failed.png deleted file mode 100644 index 1f1bafd8..00000000 Binary files a/img/pr-detailed-failed.png and /dev/null differ diff --git a/img/pr-detailed-passed.png b/img/pr-detailed-passed.png deleted file mode 100644 index 3f24d599..00000000 Binary files a/img/pr-detailed-passed.png and /dev/null differ diff --git a/img/pr-detailed.png b/img/pr-detailed.png deleted file mode 100644 index a9616f45..00000000 Binary files a/img/pr-detailed.png and /dev/null differ diff --git a/img/pr-overview-failed.png b/img/pr-overview-failed.png deleted file mode 100644 index 119e1017..00000000 Binary files a/img/pr-overview-failed.png and /dev/null differ diff --git a/img/pr-overview-passed.png b/img/pr-overview-passed.png deleted file mode 100644 index 573bb710..00000000 Binary files a/img/pr-overview-passed.png and /dev/null differ diff --git a/img/pr-overview.png b/img/pr-overview.png deleted file mode 100644 index 5aef5e46..00000000 Binary files a/img/pr-overview.png and /dev/null differ diff --git a/img/travis-ci-config.png b/img/travis-ci-config.png deleted file mode 100644 index d0af09a6..00000000 Binary files a/img/travis-ci-config.png and /dev/null differ diff --git a/img/travis-running.png b/img/travis-running.png deleted file mode 100644 index 069af72a..00000000 Binary files a/img/travis-running.png and /dev/null differ