Skip to content

Commit

Permalink
e2e tests (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-smith authored Feb 4, 2022
1 parent f053eae commit 8afcb6c
Show file tree
Hide file tree
Showing 30 changed files with 1,361 additions and 451 deletions.
96 changes: 84 additions & 12 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:

jobs:
build:

strategy:
matrix:
runner-os: [windows-latest, ubuntu-latest, macos-latest]
Expand Down Expand Up @@ -43,14 +42,7 @@ jobs:
run: dotnet build src/OctoshiftCLI.sln --no-restore /p:TreatWarningsAsErrors=true

- name: Unit Test
run: dotnet test src/OctoshiftCLI.sln --filter FullyQualifiedName\!~Integration --no-build --verbosity normal --logger:"junit;LogFilePath=unit-tests.xml" --collect:"XPlat Code Coverage" --results-directory ./coverage

- name: Integration Test
if: false
env:
ADO_PAT: ${{ secrets.ADO_PAT }}
GH_PAT: ${{ secrets.GH_PAT }}
run: dotnet test src/OctoshiftCLI.sln --filter FullyQualifiedName\~Integration --no-build --verbosity normal --logger:"junit;LogFilePath=integration-tests.xml"
run: dotnet test src/OctoshiftCLI.Tests/OctoshiftCLI.Tests.csproj --no-build --verbosity normal --logger:"junit;LogFilePath=unit-tests.xml" --collect:"XPlat Code Coverage" --results-directory ./coverage

- name: Copy Coverage To Predictable Location
run: cp coverage/**/coverage.cobertura.xml coverage/coverage.cobertura.xml
Expand All @@ -76,17 +68,97 @@ jobs:
if: matrix.runner-os == 'ubuntu-latest'
with:
files: "**/*-tests.xml"
check_name: "Test Results"
check_name: "Unit Test Results"

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
if: matrix.runner-os == 'ubuntu-latest'

publish:
integration-test:
strategy:
matrix:
runner-os: [windows-latest, ubuntu-latest, macos-latest]
runs-on: ${{ matrix.runner-os }}
concurrency: integration-test-${{ matrix.runner-os }}
steps:
- uses: actions/checkout@v2

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x

- name: Build Artifacts
run: ./publish.ps1
shell: pwsh

- name: Upload Binaries
uses: actions/upload-artifact@v2
if: matrix.runner-os == 'ubuntu-latest'
with:
name: publish-binaries
path: |
dist/
!dist/*.tar.gz
!dist/*.zip
- name: Copy binary to root (linux)
if: matrix.runner-os == 'ubuntu-latest'
run: Copy-Item ./dist/linux-x64/gei-linux-amd64 ./gh-gei
shell: pwsh

- name: Copy binary to root (windows)
if: matrix.runner-os == 'windows-latest'
run: Copy-Item ./dist/win-x64/gei-windows-amd64.exe ./gh-gei.exe
shell: pwsh

- name: Copy binary to root (macos)
if: matrix.runner-os == 'macos-latest'
run: Copy-Item ./dist/osx-x64/gei-darwin-amd64 ./gh-gei
shell: pwsh

- name: Install GH extension
run: gh extension install .
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Integration Test
env:
ADO_PAT: ${{ secrets.ADO_PAT }}
GH_PAT: ${{ secrets.GH_PAT }}
run: dotnet test src/OctoshiftCLI.IntegrationTests/OctoshiftCLI.IntegrationTests.csproj --logger:"junit;LogFilePath=integration-tests.xml"

- name: Publish Integration Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: matrix.runner-os == 'ubuntu-latest'
with:
files: "**/*-tests.xml"
check_name: "Integration Test Results"

- name: Upload test logs
uses: actions/upload-artifact@v2
if: always()
with:
name: integration-test-logs-${{ matrix.runner-os }}
path: dist/**/*.log

- name: Test Logs
if: always()
run: Get-ChildItem . -Filter *.octoshift.log -Recurse | ForEach-Object { Get-Content -Path $_.FullName }
working-directory: ./dist
shell: pwsh

- name: Test Logs (Verbose)
if: always()
run: Get-ChildItem . -Filter *.octoshift.verbose.log -Recurse | ForEach-Object { Get-Content -Path $_.FullName }
working-directory: ./dist
shell: pwsh

publish:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
needs: build
needs: [ build, integration-test ]
environment: PUBLISH_RELEASE

steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,4 @@ MigrationBackup/

/dist
/src/gei/Properties/launchSettings.json
/src/OctoshiftCLI.IntegrationTests/Properties/launchSettings.json
4 changes: 2 additions & 2 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

- Adds the ability to migrate ADO repos using the `gh gei` CLI. This overlaps with some of the capabilities of ado2gh, but the `gh gei` will not include all the extra ADO migration capabilities like re-wiring pipelines and boards integration.
- `gh gei generate-script` now has an `--ado-source-org` option
- `gh gei migrate-repo` now has `--ado-source-org` and `--ado-team-project` options
- Added `grant-migrator-role` and `revoke-migrator-role` commands to `gh gei`
- Add gei command path for generating a migration archive `gh gei generate-archive` which uses the migration api on that instance to generate two archives of data, the metadata for a repository and the git data for that repository (this will primarily be useful for migrations from GHES)
- Add gei command path for generating a migration archive `gh gei generate-archive` which uses the migration api on that instance to generate two archives of data, the metadata for a repository and the git data for that repository (this will primarily be useful for migrations from GHES)
- The script generated from generate-script will now stop on the first command that fails. Previously this script could be renamed between .ps1 and .sh, but with this change it will now only work as a .ps1 script.
10 changes: 10 additions & 0 deletions publish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}

if (Test-Path -Path ./dist/win-x64/gei-windows-amd64.exe) {
Remove-Item ./dist/win-x64/gei-windows-amd64.exe
}
if (Test-Path -Path ./dist/linux-x64/gei-linux-amd64) {
Remove-Item ./dist/linux-x64/gei-linux-amd64
}
if (Test-Path -Path ./dist/osx-x64/gei-darwin-amd64) {
Remove-Item ./dist/osx-x64/gei-darwin-amd64
}

Rename-Item ./dist/win-x64/gei.exe gei-windows-amd64.exe
Rename-Item ./dist/linux-x64/gei gei-linux-amd64
Rename-Item ./dist/osx-x64/gei gei-darwin-amd64
24 changes: 16 additions & 8 deletions src/Octoshift/AdoApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using OctoshiftCLI.Extensions;
Expand Down Expand Up @@ -262,8 +264,20 @@ public virtual async Task<string> GetTeamProjectId(string org, string teamProjec
public virtual async Task<string> GetRepoId(string org, string teamProject, string repo)
{
var url = $"https://dev.azure.com/{org}/{teamProject}/_apis/git/repositories/{repo}?api-version=4.1";
var response = await _client.GetAsync(url);
return (string)JObject.Parse(response)["id"];
try
{
var response = await _client.GetAsync(url);
return (string)JObject.Parse(response)["id"];
}
catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
{
// The repo may be disabled, can still get the ID by getting it from the repo list
url = $"https://dev.azure.com/{org}/{teamProject}/_apis/git/repositories?api-version=4.1";

var response = await _client.GetWithPagingAsync(url);

return (string)response.Single(x => ((string)x["name"]) == repo)["id"];
}
}

public virtual async Task<IEnumerable<string>> GetPipelines(string org, string teamProject, string repoId)
Expand Down Expand Up @@ -458,12 +472,6 @@ public virtual async Task CreateBoardsGithubConnection(string org, string orgId,
await _client.PostAsync(url, payload);
}

private string BuildRepoString(IEnumerable<string> repoIds)
{
var result = string.Join("\",\"", repoIds);
return $"\"{result}\"";
}

public virtual async Task DisableRepo(string org, string teamProject, string repoId)
{
var url = $"https://dev.azure.com/{org}/{teamProject}/_apis/git/repositories/{repoId}?api-version=6.1-preview.1";
Expand Down
4 changes: 3 additions & 1 deletion src/Octoshift/AdoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public AdoClient(OctoLogger log, HttpClient httpClient, string personalAccessTok

public virtual async Task<string> GetAsync(string url) => await SendAsync(HttpMethod.Get, url);

public virtual async Task<string> DeleteAsync(string url) => await SendAsync(HttpMethod.Delete, url);

public virtual async Task<string> PostAsync(string url, object body) => await SendAsync(HttpMethod.Post, url, body);

public virtual async Task<string> PutAsync(string url, object body) => await SendAsync(HttpMethod.Put, url, body);
Expand Down Expand Up @@ -91,7 +93,7 @@ public virtual async Task<JArray> GetWithPagingAsync(string url, string continua

if (!string.IsNullOrWhiteSpace(continuationToken))
{
if (!updatedUrl.Contains("?"))
if (!updatedUrl.Contains('?'))
{
updatedUrl += "?";
}
Expand Down
18 changes: 6 additions & 12 deletions src/Octoshift/GithubApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,6 @@ public virtual async Task RemoveTeamMember(string org, string teamName, string m
await _client.DeleteAsync(url);
}

public virtual async Task<(string id, string name, string description)> GetIdpGroup(string org, string idpGroupName)
{
var url = $"https://api.github.com/orgs/{org}/team-sync/groups";

var response = await _client.GetAsync(url);
var data = JObject.Parse(response);

return data["groups"].Children()
.Select(x => (id: (string)x["group_id"], name: (string)x["group_name"], description: (string)x["group_description"]))
.Single(x => x.name.ToLower() == idpGroupName.ToLower());
}

public virtual async Task AddTeamSync(string org, string teamName, string groupId, string groupName, string groupDesc)
{
var url = $"https://api.github.com/orgs/{org}/teams/{teamName}/team-sync/group-mappings";
Expand Down Expand Up @@ -306,6 +294,12 @@ public virtual async Task<bool> RevokeMigratorRole(string org, string actor, str
}
}

public virtual async Task DeleteRepo(string org, string repo)
{
var url = $"https://api.github.com/repos/{org}/{repo}";
await _client.DeleteAsync(url);
}

public virtual async Task<int> StartGitArchiveGeneration(string apiUrl, string org, string repo)
{
var url = $"{apiUrl}/orgs/{org}/migrations";
Expand Down
Loading

0 comments on commit 8afcb6c

Please sign in to comment.