Skip to content

Commit

Permalink
Optimise pipeline for release and daily operation (#222)
Browse files Browse the repository at this point in the history
refactor gh-action, optimize pipeline for release and daily operation, refactor linter
  • Loading branch information
Vad1mo authored Oct 26, 2024
1 parent 1048108 commit 66dd629
Show file tree
Hide file tree
Showing 15 changed files with 260 additions and 208 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Main and Pull Request Pipeline

on:
push:
branches: [main]
pull_request:
paths-ignore:
- '*.md'
- 'assets/**'

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Dagger Version
uses: sagikazarmark/[email protected]

- name: Run Dagger golangci-lint
uses: dagger/dagger-for-github@v6
with:
version: ${{ steps.dagger_version.outputs.version }}
verb: call
args: lint-report export --path=golangci-lint-report.sarif

- uses: reviewdog/action-setup@v1
- name: Run Reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
reviewdog -f=sarif -name="Golang Linter Report" -reporter=github-check -filter-mode nofilter -fail-level any -tee < golangci-lint-report.sarif
test-code:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Run Tests
uses: dagger/dagger-for-github@v6
with:
version: ${{ steps.dagger_version.outputs.version }}
verb: call
args: test

- name: Build Binary
uses: dagger/dagger-for-github@v6
with:
version: ${{ steps.dagger_version.outputs.version }}
verb: call
args: build-dev --platform linux/amd64

push-snapshop-release:
permissions:
contents: write
packages: write

if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs:
- lint
- test-code
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Dagger Version
uses: sagikazarmark/[email protected]

- name: Push Release
uses: dagger/dagger-for-github@v6
with:
version: ${{ steps.dagger_version.outputs.version }}
verb: call
args: snapshot-release --github-token=${{ env.GITHUB_TOKEN }}
35 changes: 0 additions & 35 deletions .github/workflows/docker_publish.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/publish_release.yml

This file was deleted.

59 changes: 0 additions & 59 deletions .github/workflows/pull-request.yml

This file was deleted.

69 changes: 69 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Release Artifacts and Container Images

on:
push:
tags:
- "v*"
branches: [main]

permissions:
contents: write
packages: write

jobs:
publish-release:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Call Dagger Function
uses: dagger/dagger-for-github@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
version: "latest"
verb: call
args: release --github-token='env:${{ env.GITHUB_TOKEN }}'

publish-images:
runs-on: ubuntu-latest
environment: PROD
env:
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
COSIGN_KEY: ${{ secrets.COSIGN_KEY }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
REGISTRY_ADDRESS: ${{ vars.REGISTRY_ADDRESS }}
PUBLISH_ADDRESS: ${{ vars.PUBLISH_ADDRESS }}
TAG: ${{ github.ref_name }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Call Docker-Publish Function
uses: dagger/dagger-for-github@v6
with:
version: "latest"
verb: call
args: "publish-image --cosign-password='env:${{ env.COSIGN_PASSWORD }}' --cosign-key='env:${{ env.COSIGN_KEY }}' --reg-username='${{ env.REGISTRY_USERNAME }}' --reg-password='env:${{ env.REGISTRY_PASSWORD }}' --reg-address='${{ env.REGISTRY_ADDRESS }}' --publish-address='${{ env.PUBLISH_ADDRESS }}' --tag='${{ env.TAG }}'"
- name: Notify on success
if: success()
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
body: "Container image published successfully! 🎉"
})
- name: Notify on failure
if: failure()
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
body: "Failed to publish Container image. ❌"
})
22 changes: 13 additions & 9 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@

run:
timeout: 3m
linters:
enable:
# default linters
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
# Default linters are already enabled, these are the additional ones
- typecheck
- unused

- gofmt
- gosec
- nilnil
# - wrapcheck
# - gocritic
# - revive #, enable once current issues are resolved
issues:
exclude-dirs:
- dagger/internal
exclude-files:
- ^.*\\.gen\\.go$
7 changes: 5 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: 2
project_name: harbor
project_name: harbor-cli

before:
hooks:
Expand Down Expand Up @@ -47,8 +47,11 @@ sboms:

checksum:
name_template: 'checksums.txt'

snapshot:
version_template: "{{ .Tag }}-next"
name_template: "HarborCLI Snapshot {{.Commit}}"
publish: true

release:
name_template: "HarborCLI {{.Tag}}"
draft: false # Set to false to ensure that releases are published, not kept as drafts
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Use "harbor [command] --help" for more information about a command.
#### Log in to Harbor Registry

```bash
harbor login demo.goharbor.io -u admin -p Harbor12345
harbor login demo.goharbor.io -u harbor-cli -p Harbor12345
```

#### Create a New Project
Expand Down Expand Up @@ -123,13 +123,15 @@ Make sure you have latest [Dagger](https://docs.dagger.io/) installed in your sy
#### Using Dagger
```bash
git clone https://github.com/goharbor/harbor-cli.git && cd harbor-cli
dagger call build-dev --platform darwin/arm64 export --path=./harbor-dev
dagger call build-dev --platform darwin/arm64 export --path=./harbor-cli
./harbor-dev --help
```

If golang is installed in your system, you can also build the project using the following commands:

```bash
git clone https://github.com/goharbor/harbor-cli.git
dagger call build
go build -o harbor-cli cmd/harbor/main.go
```


Expand Down
5 changes: 3 additions & 2 deletions dagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"dependencies": [
{
"name": "cosign",
"source": "github.com/scottames/daggerverse/cosign@8359122a7b90f2c8c6f3165570fdcbec6e923023"
"source": "github.com/scottames/daggerverse/cosign@8359122a7b90f2c8c6f3165570fdcbec6e923023",
"pin": "8359122a7b90f2c8c6f3165570fdcbec6e923023"
}
],
"source": "dagger",
"engineVersion": "v0.13.5"
"engineVersion": "v0.13.6"
}
11 changes: 7 additions & 4 deletions dagger/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module dagger/harbor-cli
go 1.23.1

require (
github.com/99designs/gqlgen v0.17.49
github.com/99designs/gqlgen v0.17.55
github.com/Khan/genqlient v0.7.0
github.com/vektah/gqlparser/v2 v2.5.16
github.com/vektah/gqlparser/v2 v2.5.17
go.opentelemetry.io/otel v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240518090000-14441aefdf88
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.3.0
Expand All @@ -28,10 +28,13 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/sosodev/duration v1.3.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0
go.opentelemetry.io/otel/sdk/metric v1.27.0
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
Expand Down
Loading

0 comments on commit 66dd629

Please sign in to comment.