Skip to content

Commit

Permalink
Merge branch 'ci-linux'
Browse files Browse the repository at this point in the history
# Conflicts:
#	build-release.ps1
  • Loading branch information
christianspecht committed Aug 6, 2023
2 parents 90651f0 + 1dc9b2c commit ef4698a
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root = true

[*.ps1]
indent_style = space
indent_size = 4
41 changes: 41 additions & 0 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "Linux build"

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 3.1.x
- name: Set version number
run: .\version-number.ps1
shell: pwsh
- name: Run build script
env:
Tests_Github_Name : ${{ secrets.Tests_Github_Name }}
Tests_Github_PW : ${{ secrets.Tests_Github_PW }}
Tests_Github_RepoPrivate : ${{ secrets.Tests_Github_RepoPrivate }}
Tests_Bitbucket_Name : ${{ secrets.Tests_Bitbucket_Name }}
Tests_Bitbucket_PW : ${{ secrets.Tests_Bitbucket_PW }}
Tests_Bitbucket_RepoPrivateGit : ${{ secrets.Tests_Bitbucket_RepoPrivateGit }}
Tests_Gitlab_Name : ${{ secrets.Tests_Gitlab_Name }}
Tests_Gitlab_PW : ${{ secrets.Tests_Gitlab_PW }}
Tests_Gitlab_RepoPrivate : ${{ secrets.Tests_Gitlab_RepoPrivate }}
run: ./build-release.ps1
shell: pwsh
- name: Upload application
uses: actions/upload-artifact@v3
with:
name: Application
path: release/scm-backup-*.zip
- name: Upload test log
uses: actions/upload-artifact@v3
with:
name: Test log
path: src/ScmBackup.Tests.Integration/bin/Release/netcoreapp3.1/*.log
5 changes: 3 additions & 2 deletions build-release.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Write-Host '###### INITIALIZE ######'

if ($env:APPVEYOR) {
if ($env:APPVEYOR -Or $env:GITHUB_ACTIONS) {

# We are on AppVeyor
# - environment variables are set in the AppVeyor settings
Expand Down Expand Up @@ -65,4 +65,5 @@ if ($LASTEXITCODE -eq 1) {
''
Write-Host '###### ZIP ######'
Copy-Item -Path .\LICENSE.txt -Destination .\release\bin\
7z a -r "release\$release_filename.zip" .\release\bin\*
$zippath = Join-Path "release" "$release_filename.zip"
7z a -r $zippath .\release\bin\*
18 changes: 9 additions & 9 deletions environment-variables.ps1.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

Write-Host 'Setting environment variables for integration tests...'

$env:Github_Name = 'scm-backup-testuser' # User for authentication. Must have read permission for private repo.
$env:Github_PW = 'not-the-real-password' # the user's personal access token
$env:Github_RepoPrivate = 'scm-backup-test-private' # a private repository
$env:Tests_Github_Name = 'scm-backup-testuser' # User for authentication. Must have read permission for private repo.
$env:Tests_Github_PW = 'not-the-real-password' # the user's personal access token
$env:Tests_Github_RepoPrivate = 'scm-backup-test-private' # a private repository

$env:Bitbucket_Name = 'scm-backup-testuser' # User for authentication. Must have read permission for private repo.
$env:Bitbucket_PW = 'not-the-real-password' # the user's app password
$env:Bitbucket_RepoPrivateGit = 'scm-backup-test-private-git' # a private repository
$env:Tests_Bitbucket_Name = 'scm-backup-testuser' # User for authentication. Must have read permission for private repo.
$env:Tests_Bitbucket_PW = 'not-the-real-password' # the user's app password
$env:Tests_Bitbucket_RepoPrivateGit = 'scm-backup-test-private-git' # a private repository

$env:Gitlab_Name = 'scm-backup-testuser' # User for authentication. Must have read permission for private repo.
$env:Gitlab_PW = 'not-the-real-password' # the user's personal access token
$env:Gitlab_RepoPrivate = 'scm-backup-test-private' # a private repository
$env:Tests_Gitlab_Name = 'scm-backup-testuser' # User for authentication. Must have read permission for private repo.
$env:Tests_Gitlab_PW = 'not-the-real-password' # the user's personal access token
$env:Tests_Gitlab_RepoPrivate = 'scm-backup-test-private' # a private repository
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

![SCM Backup logo](https://scm-backup.org/img/logo128x128.png)

[![Build status](https://ci.appveyor.com/api/projects/status/a28uyjw91iim9wv9?svg=true)](https://ci.appveyor.com/project/ChristianSpecht/scm-backup)
[![Windows Build status](https://ci.appveyor.com/api/projects/status/a28uyjw91iim9wv9?svg=true)](https://ci.appveyor.com/project/ChristianSpecht/scm-backup)
[![Linux Build status](https://github.com/christianspecht/scm-backup/actions/workflows/ci-linux.yml/badge.svg)](https://github.com/christianspecht/scm-backup/actions/workflows/ci-linux.yml)

SCM Backup is a tool which makes offline backups of your cloud hosted source code repositories, by cloning them. It supports backing up from multiple source code hosters and backing up multiple users/teams per source code hoster.
At the moment, the following hosters are supported:
Expand All @@ -12,7 +13,7 @@ At the moment, the following hosters are supported:
- [GitLab](https://gitlab.com)


And it's written in [.NET Core](https://dotnet.github.io/), which means that it's supposed to run on Windows, Linux **and** MacOS.
And it's written in [.NET Core](https://dotnet.github.io/), which means that it runs on Windows, Linux **and** MacOS.


- [Website](https://scm-backup.org)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class BitbucketApiTests : IHosterApiTests

internal override string EnvVarPrefix
{
get { return "Bitbucket"; }
get { return "Tests_Bitbucket"; }
}

internal override string ConfigHoster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace ScmBackup.Tests.Integration.Hosters
{
public class BitbucketBackupGitTests : IBackupTests
{
private string prefix = "Bitbucket";
private string prefix = "Tests_Bitbucket";

internal override string PublicUserName { get { return "scm-backup-testuser"; } }
internal override string PublicRepoName { get { return "scm-backup-test-git"; } }
Expand Down
2 changes: 1 addition & 1 deletion src/ScmBackup.Tests.Integration/Hosters/GithubApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class GithubApiTests : IHosterApiTests

internal override string EnvVarPrefix
{
get { return "Github"; }
get { return "Tests_Github"; }
}

internal override string ConfigHoster
Expand Down
9 changes: 5 additions & 4 deletions src/ScmBackup.Tests.Integration/Hosters/GithubBackupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ namespace ScmBackup.Tests.Integration.Hosters
public class GithubBackupTests : IBackupTests
{
private List<HosterRepository> repoList;
private string prefix = "Tests_Github";

internal override string PublicUserName { get { return "scm-backup-testuser"; } }
internal override string PublicRepoName { get { return "scm-backup"; } }

internal override string PrivateUserName { get { return TestHelper.EnvVar("Github_Name"); } }
internal override string PrivateRepoName { get { return TestHelper.EnvVar("Github_RepoPrivate"); } }
internal override string PrivateUserName { get { return TestHelper.EnvVar(prefix, "Name"); } }
internal override string PrivateRepoName { get { return TestHelper.EnvVar(prefix, "RepoPrivate"); } }

protected override bool SkipTestsIssue15()
{
Expand All @@ -30,8 +31,8 @@ protected override void Setup(bool usePrivateRepo)
this.source.Hoster = "github";
this.source.Type = "user";
this.source.Name = this.GetUserName(usePrivateRepo);
this.source.AuthName = TestHelper.EnvVar("Github_Name");
this.source.Password = TestHelper.EnvVar("Github_PW");
this.source.AuthName = TestHelper.EnvVar(prefix, "Name");
this.source.Password = TestHelper.EnvVar(prefix, "PW");

var config = new Config();
config.Sources.Add(this.source);
Expand Down
2 changes: 1 addition & 1 deletion src/ScmBackup.Tests.Integration/Hosters/GitlabApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class GitlabApiTests : IHosterApiTests

internal override string HosterPrivateRepo { get { return TestHelper.EnvVar(this.EnvVarPrefix, "RepoPrivate"); } }

internal override string EnvVarPrefix { get { return "Gitlab"; } }
internal override string EnvVarPrefix { get { return "Tests_Gitlab"; } }

internal override string ConfigHoster { get { return "gitlab"; } }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace ScmBackup.Tests.Integration.Hosters
{
public class GitlabBackupTests : IBackupTests
{
private string prefix = "Gitlab";
private string prefix = "Tests_Gitlab";

internal override string PublicUserName { get { return "scm-backup-testuser"; } }
internal override string PublicRepoName { get { return "scm-backup-test"; } }
Expand Down
2 changes: 1 addition & 1 deletion src/ScmBackup.Tests.Integration/Scm/CommandLineScmTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void ExecuteReturnsOutput()

var result = sut.ExecuteCommandDirectly();

Assert.Equal(sut.FakeCommandResult, result);
Assert.Contains(sut.FakeCommandResult, result);
}

[Fact]
Expand Down
10 changes: 8 additions & 2 deletions src/ScmBackup.Tests.Integration/Scm/FakeCommandLineScm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ public FakeCommandLineScm()
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
throw new NotImplementedException();
string tmppath = Path.Combine(testAssemblyDir, @"Scm/FakeCommandLineScmTools/FakeCommandLineScm-Command-Linux.sh");

this.FakeCommandName = "/bin/bash";
this.FakeCommandArgs = "-c \"chmod +x " + tmppath + " && " + tmppath + "\"";
this.FakeCommandResult = "Test Linux";

this.FakeCommandNameNotExisting = Path.Combine(testAssemblyDir, "doesnt-exist");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
throw new NotImplementedException();
throw new NotImplementedException("FakeCommandLineScm is not implemented for OSX");
}

this.context = new FakeContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "Test Linux"
4 changes: 2 additions & 2 deletions src/ScmBackup.Tests.Integration/Scm/GitScmTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ internal override string PublicRepoUrl

internal override string PrivateRepoUrl
{
get { return CloneUrlBuilder.BitbucketCloneUrl(TestHelper.EnvVar("Bitbucket_Name"), TestHelper.EnvVar("Bitbucket_RepoPrivateGit")); }
get { return CloneUrlBuilder.BitbucketCloneUrl(TestHelper.EnvVar("Tests_Bitbucket_Name"), TestHelper.EnvVar("Tests_Bitbucket_RepoPrivateGit")); }
}

internal override ScmCredentials PrivateRepoCredentials
{
get { return new ScmCredentials(TestHelper.EnvVar("Bitbucket_Name"), TestHelper.EnvVar("Bitbucket_PW")); }
get { return new ScmCredentials(TestHelper.EnvVar("Tests_Bitbucket_Name"), TestHelper.EnvVar("Tests_Bitbucket_PW")); }
}

internal override string NonExistingRepoUrl
Expand Down
4 changes: 2 additions & 2 deletions src/ScmBackup.Tests.Integration/Scm/MercurialScmTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ internal override string PublicRepoUrl

internal override string PrivateRepoUrl
{
get { return CloneUrlBuilder.BitbucketCloneUrl(TestHelper.EnvVar("Bitbucket_Name"), TestHelper.EnvVar("Bitbucket_RepoPrivate")); }
get { return CloneUrlBuilder.BitbucketCloneUrl(TestHelper.EnvVar("Tests_Bitbucket_Name"), TestHelper.EnvVar("Tests_Bitbucket_RepoPrivate")); }
}

internal override ScmCredentials PrivateRepoCredentials
{
get { return new ScmCredentials(TestHelper.EnvVar("Bitbucket_Name"), TestHelper.EnvVar("Bitbucket_PW")); }
get { return new ScmCredentials(TestHelper.EnvVar("Tests_Bitbucket_Name"), TestHelper.EnvVar("Tests_Bitbucket_PW")); }
}

internal override string NonExistingRepoUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<None Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Scm\FakeCommandLineScmTools\FakeCommandLineScm-Command-Linux.sh">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Scm\FakeCommandLineScmTools\FakeCommandLineScm-Command-Windows.bat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
18 changes: 16 additions & 2 deletions version-number.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@
else {
# regular CI build, no release
$shortversion = '0.0.0'
$longversion = '0.0.0.CI-' + $env:APPVEYOR_BUILD_NUMBER + '-' + $commit
$longversion = '0.0.0.CI-WIN-' + $env:APPVEYOR_BUILD_NUMBER + '-' + $commit
}
}
elseif ($env:GITHUB_ACTIONS) {

# GH Actions
$commit = $env:GITHUB_SHA.Substring(0,7)
$shortversion = '0.0.0'
$longversion = '0.0.0.CI-LINUX-' + $env:GITHUB_RUN_NUMBER + '-' + $commit
}
else {

# local build
Expand All @@ -31,4 +38,11 @@ $env:ScmBackupLongVersion=$longversion

Write-Host 'Commit: ' $env:ScmBackupCommit
Write-Host 'Short Version: ' $env:ScmBackupShortVersion
Write-Host 'Long Version: ' $env:ScmBackupLongVersion
Write-Host 'Long Version: ' $env:ScmBackupLongVersion

if ($env:GITHUB_ACTIONS) {
# for GH Actions, save version numbers so they are available in subsequent steps
"ScmBackupCommit=$commit" >> $env:GITHUB_ENV
"ScmBackupShortVersion=$shortversion" >> $env:GITHUB_ENV
"ScmBackupLongVersion=$longversion" >> $env:GITHUB_ENV
}

0 comments on commit ef4698a

Please sign in to comment.