Skip to content
Open

New #188

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7316344
transition A to GA
kgerot Mar 25, 2022
0575d90
altering yaml file
kgerot Mar 25, 2022
d61867b
yaml fix
kgerot Mar 25, 2022
63afc73
yaml fix2
kgerot Mar 25, 2022
bdc1dfb
attempt using msbuild
kgerot Mar 25, 2022
6dfb8bd
added vs build frameworks package
kgerot Mar 25, 2022
351632b
altered grammar
kgerot Mar 25, 2022
9ef5c8f
altered grammar
kgerot Mar 25, 2022
a751367
altered grammar
kgerot Mar 25, 2022
f2022ac
nuget restore
kgerot Mar 25, 2022
7a4e157
added nuget
kgerot Mar 25, 2022
63a9cba
replace action with basi
kgerot Mar 25, 2022
bd67b03
altered Readme
kgerot Mar 25, 2022
9048174
unit tests
kgerot Mar 25, 2022
05b0831
unit tests addition readme
kgerot Mar 25, 2022
db5c9e4
image?
kgerot Mar 25, 2022
7086e66
Test Push
kgerot Mar 25, 2022
e9b2788
Failed Unit Test
kgerot Mar 25, 2022
1b76479
Failed Unit Test
kgerot Mar 25, 2022
f9df0ea
fixed
kgerot Mar 25, 2022
ef915ed
namespace resolution
kgerot Mar 25, 2022
a4b06ee
Final Readme
kgerot Mar 25, 2022
2096fc0
Final Updates for Lab
kgerot Mar 25, 2022
65a9d7a
Merge pull request #2 from kgerot/dev
kgerot Mar 25, 2022
762ab86
Update README.md
kgerot Mar 25, 2022
92d8348
Update README.md
kgerot Mar 28, 2022
1587f42
Update README.md
kgerot Mar 31, 2022
0a253dc
Update README.md
kgerot Mar 31, 2022
5960db6
Update README.md
kgerot Mar 31, 2022
3c9600b
Update README.md
kgerot Apr 4, 2022
594366d
Update README.md
kgerot Nov 9, 2022
ff193a8
Update README.md
kgerot Nov 21, 2022
4653e9d
Update README.md
kgerot Nov 21, 2022
982a973
Update README.md to re-run Basic Action
kgerot Apr 13, 2024
8131b12
Update README.md to reset action
kgerot Apr 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/run-app.yaml
Original file line number Diff line number Diff line change
@@ -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!"
24 changes: 23 additions & 1 deletion Console/Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
<OutputType>Exe</OutputType>
<RootNamespace>TravisCI</RootNamespace>
<AssemblyName>TravisCI</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -32,8 +35,19 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Build.Framework.17.1.0\lib\net472\Microsoft.Build.Framework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.Setup.Configuration.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.VisualStudio.Setup.Configuration.Interop.3.0.4492\lib\net35\Microsoft.VisualStudio.Setup.Configuration.Interop.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -47,6 +61,14 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.VisualStudio.Setup.Configuration.Interop.3.0.4492\build\Microsoft.VisualStudio.Setup.Configuration.Interop.targets" Condition="Exists('..\packages\Microsoft.VisualStudio.Setup.Configuration.Interop.3.0.4492\build\Microsoft.VisualStudio.Setup.Configuration.Interop.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.VisualStudio.Setup.Configuration.Interop.3.0.4492\build\Microsoft.VisualStudio.Setup.Configuration.Interop.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VisualStudio.Setup.Configuration.Interop.3.0.4492\build\Microsoft.VisualStudio.Setup.Configuration.Interop.targets'))" />
</Target>
</Project>
2 changes: 1 addition & 1 deletion Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace TravisCILab
namespace GithubActionsLab
{
public class Program
{
Expand Down
6 changes: 6 additions & 0 deletions Console/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Build.Framework" version="17.1.0" targetFramework="net48" />
<package id="Microsoft.VisualStudio.Setup.Configuration.Interop" version="3.0.4492" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net48" />
</packages>
4 changes: 2 additions & 2 deletions TravisCI.sln → GithubActions.sln
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
148 changes: 92 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 15 additions & 1 deletion Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Tests</RootNamespace>
<AssemblyName>Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -33,11 +34,22 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Build.Framework.17.1.0\lib\net472\Microsoft.Build.Framework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.Setup.Configuration.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.VisualStudio.Setup.Configuration.Interop.3.0.4492\lib\net35\Microsoft.VisualStudio.Setup.Configuration.Interop.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="nunit.framework, Version=3.9.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -64,5 +76,7 @@
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.VisualStudio.Setup.Configuration.Interop.3.0.4492\build\Microsoft.VisualStudio.Setup.Configuration.Interop.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VisualStudio.Setup.Configuration.Interop.3.0.4492\build\Microsoft.VisualStudio.Setup.Configuration.Interop.targets'))" />
</Target>
<Import Project="..\packages\Microsoft.VisualStudio.Setup.Configuration.Interop.3.0.4492\build\Microsoft.VisualStudio.Setup.Configuration.Interop.targets" Condition="Exists('..\packages\Microsoft.VisualStudio.Setup.Configuration.Interop.3.0.4492\build\Microsoft.VisualStudio.Setup.Configuration.Interop.targets')" />
</Project>
2 changes: 1 addition & 1 deletion Tests/UnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using NUnit.Framework;

namespace TravisCILab
namespace GithubActionsLab
{
[TestFixture]
public class Math
Expand Down
3 changes: 3 additions & 0 deletions Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Build.Framework" version="17.1.0" targetFramework="net48" />
<package id="Microsoft.VisualStudio.Setup.Configuration.Interop" version="3.0.4492" targetFramework="net48" />
<package id="NUnit" version="3.9.0" targetFramework="net452" />
<package id="NUnit.ConsoleRunner" version="3.8.0" targetFramework="net452" />
<package id="NUnit3TestAdapter" version="3.9.0" targetFramework="net452" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net48" />
</packages>
Binary file added img/actions-tab.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/badge-markdown.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/failed-build.png
Binary file not shown.
Binary file added img/failed-job.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/failed-pull.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/follow-button.png
Binary file not shown.
Binary file added img/inner-test.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/mono-build.png
Binary file not shown.
Binary file removed img/nunit-tests.png
Binary file not shown.
Binary file added img/passed-pull.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/passing-unit-tests.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/pr-detailed-failed.png
Binary file not shown.
Binary file removed img/pr-detailed-passed.png
Binary file not shown.
Binary file removed img/pr-detailed.png
Binary file not shown.
Binary file removed img/pr-overview-failed.png
Binary file not shown.
Binary file removed img/pr-overview-passed.png
Binary file not shown.
Binary file removed img/pr-overview.png
Binary file not shown.
Binary file removed img/travis-ci-config.png
Binary file not shown.
Binary file removed img/travis-running.png
Binary file not shown.