Skip to content

cli improvments

cli improvments #3445

Workflow file for this run

name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
GOPATH: /home/runner/go/
GOPROXY: "https://proxy.golang.org"
REGISTRY_IMAGE: ghcr.io/pluralsh/plural-cli
jobs:
test:
name: Unit test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- run: make test
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: golangci-lint
uses: golangci/[email protected]
with:
version: v2.4.0
skip-cache: true
contract-validation:
name: Validate PR Contracts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- run: make install-cli
- name: Run Plural PR Contracts Validation
run: plural pr contracts --file test/contracts.yaml --validate
build-image:
name: Build image
needs: [test]
permissions:
contents: 'read'
id-token: 'write'
packages: 'write'
security-events: write
actions: read
strategy:
fail-fast: false
matrix:
platforms:
- platform: linux/amd64
runner: ubuntu-24.04
- platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.platforms.runner }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare
run: |
platform=${{ matrix.platforms.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get current date
id: date
run: echo "date=$(date -u +'%Y-%m-%dT%H:%M:%S%z')" >> $GITHUB_OUTPUT
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
context: "."
file: "./Dockerfile"
tags: ${{ env.REGISTRY_IMAGE }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.platforms.platform }}
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
APP_VSN=dev
APP_COMMIT=${{ github.sha }}
APP_DATE=${{ steps.date.outputs.date }}
- name: Export digest
run: |
mkdir -p ${{ runner.temp }}/digests
digest="${{ steps.build.outputs.digest }}"
touch "${{ runner.temp }}/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
publish-image:
name: Publish image
needs: [build-image]
runs-on: ubuntu-latest
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/pluralsh/plural-cli
tags: |
type=sha
type=ref,event=pr
type=ref,event=branch
- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Run Trivy vulnerability scanner on cli image
uses: aquasecurity/trivy-action@master
with:
scan-type: 'image'
image-ref: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
hide-progress: false
format: 'sarif'
output: 'trivy-results.sarif'
scanners: 'vuln'
ignore-unfixed: true
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'
# cloud:
# name: Build cloud image
# runs-on: ubuntu-latest
# permissions:
# contents: 'read'
# id-token: 'write'
# packages: 'write'
# security-events: write
# actions: read
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# - name: Docker meta
# id: meta
# uses: docker/metadata-action@v4
# with:
# # list of Docker images to use as base name for tags
# images: |
# ghcr.io/pluralsh/plural-cli-cloud
# # generate Docker tags based on the following events/attributes
# tags: |
# type=sha
# type=ref,event=pr
# type=ref,event=branch
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
# - name: Login to GHCR
# uses: docker/login-action@v2
# with:
# registry: ghcr.io
# username: ${{ github.repository_owner }}
# password: ${{ secrets.GITHUB_TOKEN }}
# - name: Get current date
# id: date
# run: echo "date=$(date -u +'%Y-%m-%dT%H:%M:%S%z')" >> $GITHUB_OUTPUT
# - uses: docker/build-push-action@v6
# with:
# context: .
# file: ./dockerfiles/Dockerfile.cloud
# push: true
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
# platforms: linux/amd64,linux/arm64
# # cache-from: type=gha
# # cache-to: type=gha,mode=max
# build-args: |
# APP_VSN=dev
# APP_COMMIT=${{ github.sha }}
# APP_DATE=${{ steps.date.outputs.date }}
# - name: Run Trivy vulnerability scanner on cli cloud image
# uses: aquasecurity/trivy-action@master
# with:
# scan-type: 'image'
# image-ref: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
# hide-progress: false
# format: 'sarif'
# output: 'trivy-results.sarif'
# scanners: 'vuln'
# timeout: 10m
# ignore-unfixed: true
# #severity: 'CRITICAL,HIGH'
# - name: Upload Trivy scan results to GitHub Security tab
# uses: github/codeql-action/upload-sarif@v2
# with:
# sarif_file: 'trivy-results.sarif'
# dind:
# name: Build dind image
# runs-on: ubuntu-latest
# permissions:
# contents: 'read'
# id-token: 'write'
# packages: 'write'
# security-events: write
# actions: read
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Docker meta
# id: meta
# uses: docker/metadata-action@v4
# with:
# # list of Docker images to use as base name for tags
# images: |
# ghcr.io/pluralsh/plural-dind
# # generate Docker tags based on the following events/attributes
# tags: |
# type=sha
# type=ref,event=pr
# type=ref,event=branch
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
# - name: Login to GHCR
# uses: docker/login-action@v2
# with:
# registry: ghcr.io
# username: ${{ github.repository_owner }}
# password: ${{ secrets.GITHUB_TOKEN }}
# - name: Get current date
# id: date
# run: echo "date=$(date -u +'%Y-%m-%dT%H:%M:%S%z')" >> $GITHUB_OUTPUT
# - uses: docker/build-push-action@v6
# with:
# context: .
# file: ./dockerfiles/Dockerfile.dind
# push: true
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
# platforms: linux/amd64,linux/arm64
# # cache-from: type=gha
# # cache-to: type=gha,mode=max
# build-args: |
# APP_VSN=dev
# APP_COMMIT=${{ github.sha }}
# APP_DATE=${{ steps.date.outputs.date }}
# - name: Run Trivy vulnerability scanner on dind image
# uses: aquasecurity/trivy-action@master
# with:
# scan-type: 'image'
# image-ref: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
# hide-progress: false
# format: 'sarif'
# output: 'trivy-results.sarif'
# scanners: 'vuln'
# timeout: 10m
# ignore-unfixed: true
# #severity: 'CRITICAL,HIGH'
# - name: Upload Trivy scan results to GitHub Security tab
# uses: github/codeql-action/upload-sarif@v2
# with:
# sarif_file: 'trivy-results.sarif'
trivy-scan:
name: Trivy fs scan
runs-on: ubuntu-latest
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner in fs mode
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
hide-progress: false
format: 'sarif'
output: 'trivy-results.sarif'
scanners: 'vuln,secret'
ignore-unfixed: true
#severity: 'CRITICAL,HIGH'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'
build:
name: GoReleaser build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: GoReleaser (Build)
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser-pro
version: '~> v2'
args: build --clean --snapshot --timeout 90m
env:
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLAB_CLIENT_SECRET: ${{ secrets.GITLAB_CLIENT_SECRET }}
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}