Skip to content

Commit

Permalink
Merge pull request #214 from monitoror/develop
Browse files Browse the repository at this point in the history
Release 3.0.0 (with fixed CI/CD and doc)
  • Loading branch information
Alex-D committed Mar 4, 2020
2 parents cddf1c0 + 5f79111 commit 4d5d4b8
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 87 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/continuous-integration.yml
Expand Up @@ -123,6 +123,10 @@ jobs:
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}

- uses: actions/download-artifact@v1
with:
name: binaries
Expand All @@ -132,8 +136,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: v${{ github.ref }}
tag_name: ${{ steps.get_version.outputs.VERSION }}
release_name: v${{ steps.get_version.outputs.VERSION }}
draft: true
prerelease: true

Expand All @@ -143,7 +147,7 @@ jobs:
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: binaries/monitoror-linux-amd64
asset_name: monitoror-linux-amd64-${{ github.ref }}
asset_name: monitoror-linux-amd64-${{ steps.get_version.outputs.VERSION }}
asset_content_type: application/x-executable

- uses: actions/upload-release-asset@v1.0.1
Expand All @@ -152,7 +156,7 @@ jobs:
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: binaries/monitoror-linux-arm
asset_name: monitoror-linux-arm-${{ github.ref }}
asset_name: monitoror-linux-arm-${{ steps.get_version.outputs.VERSION }}
asset_content_type: application/x-executable

- uses: actions/upload-release-asset@v1.0.1
Expand All @@ -161,7 +165,7 @@ jobs:
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: binaries/monitoror-windows-amd64.exe
asset_name: monitoror-windows-amd64-${{ github.ref }}.exe
asset_name: monitoror-windows-amd64-${{ steps.get_version.outputs.VERSION }}.exe
asset_content_type: application/x-dosexec

- uses: actions/upload-release-asset@v1.0.1
Expand All @@ -170,5 +174,5 @@ jobs:
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: binaries/monitoror-macos
asset_name: monitoror-macos-${{ github.ref }}
asset_name: monitoror-macos-${{ steps.get_version.outputs.VERSION }}
asset_content_type: application/x-mach-binary
20 changes: 8 additions & 12 deletions docs/documentation/index.html
Expand Up @@ -185,8 +185,7 @@ <h3 id="installation">Installation</h3>
Linux <span class="m-documentation--installation-arch">x64</span>
</td>
<td>
<a class="m-documentation--installation-link" download
href="https://github.com/monitoror/monitoror/releases/latest/download/monitoror-linux-amd64">
<a class="m-documentation--installation-link" data-download-platform="linux-amd64">
<svg fill="currentColor" viewBox="0 0 72 72">
<path d="M64 27v28H8V27H0v36h72V27h-8z"></path>
<path d="M32.1 6.7h8v33.6h-8z"></path>
Expand All @@ -196,16 +195,15 @@ <h3 id="installation">Installation</h3>
</a>
<br>
<input data-select-on-click readonly type="text"
value="curl -s -o monitoror https://github.com/monitoror/monitoror/releases/latest/download/monitoror-linux-amd64"/>
value="curl -sL -o monitoror $(curl -s https://api.github.com/repos/monitoror/monitoror/releases/latest | grep 'browser_download_url.*monitoror-linux-amd64' | cut -d: -f2,3 | tr -d \&quot;)"/>
</td>
</tr>
<tr>
<td>
Linux <span class="m-documentation--installation-arch">ARM</span>
</td>
<td>
<a class="m-documentation--installation-link" download
href="https://github.com/monitoror/monitoror/releases/latest/download/monitoror-linux-arm">
<a class="m-documentation--installation-link" data-download-platform="linux-arm">
<svg fill="currentColor" viewBox="0 0 72 72">
<path d="M64 27v28H8V27H0v36h72V27h-8z"></path>
<path d="M32.1 6.7h8v33.6h-8z"></path>
Expand All @@ -215,16 +213,15 @@ <h3 id="installation">Installation</h3>
</a>
<br>
<input data-select-on-click readonly type="text"
value="curl -s -o monitoror https://github.com/monitoror/monitoror/releases/latest/download/monitoror-linux-arm"/>
value="curl -sL -o monitoror $(curl -s https://api.github.com/repos/monitoror/monitoror/releases/latest | grep 'browser_download_url.*monitoror-linux-arm' | cut -d: -f2,3 | tr -d \&quot;)"/>
</td>
</tr>
<tr>
<td>
macOS
</td>
<td>
<a class="m-documentation--installation-link" download
href="https://github.com/monitoror/monitoror/releases/latest/download/monitoror-macos">
<a class="m-documentation--installation-link" data-download-platform="macos">
<svg fill="currentColor" viewBox="0 0 72 72">
<path d="M64 27v28H8V27H0v36h72V27h-8z"></path>
<path d="M32.1 6.7h8v33.6h-8z"></path>
Expand All @@ -234,16 +231,15 @@ <h3 id="installation">Installation</h3>
</a>
<br>
<input data-select-on-click readonly type="text"
value="curl -s -o monitoror https://github.com/monitoror/monitoror/releases/latest/download/monitoror-macos"/>
value="curl -sL -o monitoror $(curl -s https://api.github.com/repos/monitoror/monitoror/releases/latest | grep 'browser_download_url.*monitoror-macos' | cut -d: -f2,3 | tr -d \&quot;)"/>
</td>
</tr>
<tr>
<td>
Windows <span class="m-documentation--installation-arch">x64</span>
</td>
<td>
<a class="m-documentation--installation-link" download
href="https://github.com/monitoror/monitoror/releases/latest/download/monitoror-windows-amd64.exe">
<a class="m-documentation--installation-link" data-download-platform="windows-amd64">
<svg fill="currentColor" viewBox="0 0 72 72">
<path d="M64 27v28H8V27H0v36h72V27h-8z"></path>
<path d="M32.1 6.7h8v33.6h-8z"></path>
Expand All @@ -253,7 +249,7 @@ <h3 id="installation">Installation</h3>
</a>
<br>
<input data-select-on-click readonly type="text"
value="Invoke-WebRequest -OutFile monitoror.exe https://github.com/monitoror/monitoror/releases/latest/download/monitoror-windows-amd64.exe"/>
value="Invoke-WebRequest -OutFile monitoror.exe $(Invoke-WebRequest https://api.github.com/repos/monitoror/monitoror/releases/latest | Select-Object -Expand Content | ConvertFrom-Json | Select-Object -Expand assets | Where-Object {$_.name -Match 'windows'} | Select-Object -Expand browser_download_url)"/>
</td>
</tr>
</tbody>
Expand Down
16 changes: 15 additions & 1 deletion docs/js/main.js
Expand Up @@ -81,7 +81,6 @@
})
})


document.querySelector('.m-sidebar').addEventListener('click', (e) => {
e.stopPropagation()
})
Expand All @@ -95,6 +94,21 @@ if (typeof hljs !== 'undefined') {
hljs.initHighlightingOnLoad()
}

// Fill data-download-platform href
const downloadLinks = Array.from(document.querySelectorAll('[data-download-platform]'))
if (downloadLinks.length > 0) {
fetch('https://api.github.com/repos/monitoror/monitoror/releases/latest').then((response) => {
response.json().then((body) => {
const assets = body.assets

downloadLinks.forEach((a) => {
const downloadUrl = assets.find((asset) => asset.name.includes(a.dataset.downloadPlatform)).browser_download_url
a.href = downloadUrl
})
})
})
}

// Input with auto "select on click" behaviour
Array.from(document.querySelectorAll('[data-select-on-click]')).forEach((input) => {
input.addEventListener('click', function () {
Expand Down
64 changes: 33 additions & 31 deletions monitorable/azuredevops/usecase/azuredevops_faker.go
Expand Up @@ -7,6 +7,8 @@ import (
"math/rand"
"time"

cmap "github.com/orcaman/concurrent-map"

"github.com/monitoror/monitoror/models"
"github.com/monitoror/monitoror/monitorable/azuredevops"
azureModels "github.com/monitoror/monitoror/monitorable/azuredevops/models"
Expand All @@ -19,7 +21,7 @@ import (

type (
azureDevOpsUsecase struct {
timeRefByProject map[string]time.Time
timeRefByProject cmap.ConcurrentMap
}
)

Expand All @@ -40,16 +42,16 @@ var availableReleaseStatus = faker.Statuses{
}

func NewAzureDevOpsUsecase() azuredevops.Usecase {
return &azureDevOpsUsecase{make(map[string]time.Time)}
return &azureDevOpsUsecase{cmap.New()}
}

func (tu *azureDevOpsUsecase) Build(params *azureModels.BuildParams) (tile *models.Tile, err error) {
func (au *azureDevOpsUsecase) Build(params *azureModels.BuildParams) (tile *models.Tile, err error) {
tile = models.NewTile(azuredevops.AzureDevOpsBuildTileType).WithBuild()
tile.Label = fmt.Sprintf("%s (build-qa-%d)", params.Project, *params.Definition)
tile.Build.ID = pointer.ToString("12")
tile.Build.Branch = pointer.ToString(git.HumanizeBranch(nonempty.String(*params.Branch, "master")))

tile.Status = nonempty.Struct(params.Status, tu.computeStatus(params.Project, params.Definition, availableBuildStatus)).(models.TileStatus)
tile.Status = nonempty.Struct(params.Status, au.computeStatus(params.Project, params.Definition, availableBuildStatus)).(models.TileStatus)

if tile.Status == models.WarningStatus {
// Warning can be Unstable Build
Expand All @@ -68,23 +70,10 @@ func (tu *azureDevOpsUsecase) Build(params *azureModels.BuildParams) (tile *mode
tile.Build.Author.AvatarURL = nonempty.String(params.AuthorAvatarURL, "https://monitoror.com/assets/images/avatar.png")
}

// StartedAt / FinishedAt
if tile.Status == models.SuccessStatus || tile.Status == models.FailedStatus || tile.Status == models.WarningStatus || tile.Status == models.CanceledStatus {
min := time.Now().Unix() - int64(time.Hour.Seconds()*24*30) - 3600
max := time.Now().Unix() - 3600
delta := max - min

tile.Build.StartedAt = pointer.ToTime(nonempty.Time(params.StartedAt, time.Unix(rand.Int63n(delta)+min, 0)))
tile.Build.FinishedAt = pointer.ToTime(nonempty.Time(params.FinishedAt, tile.Build.StartedAt.Add(time.Second*time.Duration(rand.Int63n(3600)))))
}
if tile.Status == models.QueuedStatus || tile.Status == models.RunningStatus {
tile.Build.StartedAt = pointer.ToTime(nonempty.Time(params.StartedAt, time.Now().Add(-time.Second*time.Duration(rand.Int63n(3600)))))
}

// Duration / EstimatedDuration
if tile.Status == models.RunningStatus {
estimatedDuration := nonempty.Duration(time.Duration(params.EstimatedDuration), time.Second*300)
tile.Build.Duration = pointer.ToInt64(nonempty.Int64(params.Duration, int64(tu.computeDuration(params.Project, params.Definition, estimatedDuration).Seconds())))
tile.Build.Duration = pointer.ToInt64(nonempty.Int64(params.Duration, int64(au.computeDuration(params.Project, params.Definition, estimatedDuration).Seconds())))

if tile.Build.PreviousStatus != models.UnknownStatus {
tile.Build.EstimatedDuration = pointer.ToInt64(int64(estimatedDuration.Seconds()))
Expand All @@ -93,15 +82,26 @@ func (tu *azureDevOpsUsecase) Build(params *azureModels.BuildParams) (tile *mode
}
}

// StartedAt / FinishedAt
if tile.Build.Duration == nil {
tile.Build.StartedAt = pointer.ToTime(nonempty.Time(params.StartedAt, time.Now().Add(-time.Minute*10)))
} else {
tile.Build.StartedAt = pointer.ToTime(nonempty.Time(params.StartedAt, time.Now().Add(-time.Second*time.Duration(*tile.Build.Duration))))
}

if tile.Status != models.QueuedStatus && tile.Status != models.RunningStatus {
tile.Build.FinishedAt = pointer.ToTime(nonempty.Time(params.FinishedAt, tile.Build.StartedAt.Add(time.Minute*5)))
}

return
}

func (tu *azureDevOpsUsecase) Release(params *azureModels.ReleaseParams) (tile *models.Tile, err error) {
func (au *azureDevOpsUsecase) Release(params *azureModels.ReleaseParams) (tile *models.Tile, err error) {
tile = models.NewTile(azuredevops.AzureDevOpsReleaseTileType).WithBuild()
tile.Label = fmt.Sprintf("%s (release-%d)", params.Project, *params.Definition)
tile.Build.ID = pointer.ToString("12")

tile.Status = nonempty.Struct(params.Status, tu.computeStatus(params.Project, params.Definition, availableReleaseStatus)).(models.TileStatus)
tile.Status = nonempty.Struct(params.Status, au.computeStatus(params.Project, params.Definition, availableReleaseStatus)).(models.TileStatus)

if tile.Status == models.WarningStatus {
// Warning can be Unstable Build
Expand All @@ -123,7 +123,7 @@ func (tu *azureDevOpsUsecase) Release(params *azureModels.ReleaseParams) (tile *
// Duration / EstimatedDuration
if tile.Status == models.RunningStatus {
estimatedDuration := nonempty.Duration(time.Duration(params.EstimatedDuration), time.Second*300)
tile.Build.Duration = pointer.ToInt64(nonempty.Int64(params.Duration, int64(tu.computeDuration(params.Project, params.Definition, estimatedDuration).Seconds())))
tile.Build.Duration = pointer.ToInt64(nonempty.Int64(params.Duration, int64(au.computeDuration(params.Project, params.Definition, estimatedDuration).Seconds())))

if tile.Build.PreviousStatus != models.UnknownStatus {
tile.Build.EstimatedDuration = pointer.ToInt64(int64(estimatedDuration.Seconds()))
Expand All @@ -146,22 +146,24 @@ func (tu *azureDevOpsUsecase) Release(params *azureModels.ReleaseParams) (tile *
return
}

func (tu *azureDevOpsUsecase) computeStatus(project string, definition *int, statuses faker.Statuses) models.TileStatus {
func (au *azureDevOpsUsecase) computeStatus(project string, definition *int, statuses faker.Statuses) models.TileStatus {
projectID := fmt.Sprintf("%s-%d", project, *definition)
value, ok := tu.timeRefByProject[projectID]
if !ok {
tu.timeRefByProject[projectID] = faker.GetRefTime()
value, ok := au.timeRefByProject.Get(projectID)
if !ok || value == nil {
value = faker.GetRefTime()
au.timeRefByProject.Set(projectID, value)
}

return faker.ComputeStatus(value, statuses)
return faker.ComputeStatus(value.(time.Time), statuses)
}

func (tu *azureDevOpsUsecase) computeDuration(project string, definition *int, duration time.Duration) time.Duration {
func (au *azureDevOpsUsecase) computeDuration(project string, definition *int, duration time.Duration) time.Duration {
projectID := fmt.Sprintf("%s-%d", project, *definition)
value, ok := tu.timeRefByProject[projectID]
if !ok {
tu.timeRefByProject[projectID] = faker.GetRefTime()
value, ok := au.timeRefByProject.Get(projectID)
if !ok || value == nil {
value = faker.GetRefTime()
au.timeRefByProject.Set(projectID, value)
}

return faker.ComputeDuration(value, duration)
return faker.ComputeDuration(value.(time.Time), duration)
}
5 changes: 4 additions & 1 deletion monitorable/config/models/errors.go
Expand Up @@ -11,7 +11,10 @@ type ConfigFileNotFoundError struct {
}

func (e *ConfigFileNotFoundError) Error() string {
return fmt.Sprintf(`Config not found at: %s, %v`, e.PathOrURL, e.Err.Error())
if e.Err != nil {
return fmt.Sprintf(`Config not found at: %s, %v`, e.PathOrURL, e.Err.Error())
}
return fmt.Sprintf(`Config not found at: %s`, e.PathOrURL)
}
func (e *ConfigFileNotFoundError) Unwrap() error { return e.Err }

Expand Down
4 changes: 4 additions & 0 deletions monitorable/config/models/errors_test.go
Expand Up @@ -11,6 +11,10 @@ func TestConfigFileNotFoundError(t *testing.T) {
err := &ConfigFileNotFoundError{Err: errors.New("boom"), PathOrURL: "test"}
assert.Equal(t, "Config not found at: test, boom", err.Error())
assert.Equal(t, "boom", err.Unwrap().Error())

err = &ConfigFileNotFoundError{PathOrURL: "test"}
assert.Equal(t, "Config not found at: test", err.Error())
assert.Equal(t, nil, err.Unwrap())
}

func TestConfigVersionFormatError(t *testing.T) {
Expand Down
24 changes: 14 additions & 10 deletions monitorable/github/usecase/github_faker.go
Expand Up @@ -7,6 +7,8 @@ import (
"math/rand"
"time"

cmap "github.com/orcaman/concurrent-map"

"github.com/AlekSi/pointer"
"github.com/monitoror/monitoror/models"
"github.com/monitoror/monitoror/monitorable/github"
Expand All @@ -19,7 +21,7 @@ import (

type (
githubUsecase struct {
timeRefByProject map[string]time.Time
timeRefByProject cmap.ConcurrentMap
}
)

Expand All @@ -35,7 +37,7 @@ var availableBuildStatus = faker.Statuses{
}

func NewGithubUsecase() github.Usecase {
return &githubUsecase{make(map[string]time.Time)}
return &githubUsecase{cmap.New()}
}

func (gu *githubUsecase) Count(params *githubModels.CountParams) (*models.Tile, error) {
Expand Down Expand Up @@ -113,20 +115,22 @@ func (gu *githubUsecase) ListDynamicTile(params interface{}) ([]builder.Result,

func (gu *githubUsecase) computeStatus(params *githubModels.ChecksParams) models.TileStatus {
projectID := fmt.Sprintf("%s-%s-%s", params.Owner, params.Repository, params.Ref)
value, ok := gu.timeRefByProject[projectID]
if !ok {
gu.timeRefByProject[projectID] = faker.GetRefTime()
value, ok := gu.timeRefByProject.Get(projectID)
if !ok || value == nil {
value = faker.GetRefTime()
gu.timeRefByProject.Set(projectID, value)
}

return faker.ComputeStatus(value, availableBuildStatus)
return faker.ComputeStatus(value.(time.Time), availableBuildStatus)
}

func (gu *githubUsecase) computeDuration(params *githubModels.ChecksParams, duration time.Duration) time.Duration {
projectID := fmt.Sprintf("%s-%s-%s", params.Owner, params.Repository, params.Ref)
value, ok := gu.timeRefByProject[projectID]
if !ok {
gu.timeRefByProject[projectID] = faker.GetRefTime()
value, ok := gu.timeRefByProject.Get(projectID)
if !ok || value == nil {
value = faker.GetRefTime()
gu.timeRefByProject.Set(projectID, value)
}

return faker.ComputeDuration(value, duration)
return faker.ComputeDuration(value.(time.Time), duration)
}

0 comments on commit 4d5d4b8

Please sign in to comment.