Skip to content

Commit

Permalink
Merge branch 'main' into chore/reuse-aggregation-from-ctf
Browse files Browse the repository at this point in the history
  • Loading branch information
hilmarf authored Nov 6, 2024
2 parents 8349cdc + d6a5994 commit 4e55056
Show file tree
Hide file tree
Showing 48 changed files with 605 additions and 188 deletions.
56 changes: 9 additions & 47 deletions .github/workflows/publish-to-other-than-github.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,18 @@
name: Publish Release to other package registries than Github

on:
workflow_dispatch:
inputs:
version:
type: string
description: 'Version of the latest release (e.g. v0.42.0)'
required: false
default: ''
repository_dispatch:
types: [ocm-cli-release]
types: [publish-ocm-cli]

jobs:

push-to-aur:
name: Update Arch Linux User Repository
if: github.event.client_payload.push-to-aur && github.event.client_payload.version != ''
runs-on: ubuntu-latest
steps:
- name: Ensure proper version
run: |
if [ -n "${{ github.event.inputs.version }}" ]; then
echo "RELEASE_VERSION=$(echo ${{ github.event.inputs.version }} | tr -d ['v'])" >> $GITHUB_ENV
exit 0
fi
if [ -n "${{ github.event.client_payload.version }}" ]; then
echo "RELEASE_VERSION=$(echo ${{ github.event.client_payload.version }} | tr -d ['v'])" >> $GITHUB_ENV
exit 0
fi
echo "Version not provided"
exit 1
run: echo "RELEASE_VERSION=$(echo ${{ github.event.client_payload.version }} | tr -d ['v'])" >> $GITHUB_ENV
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
Expand All @@ -56,24 +40,13 @@ jobs:
push-to-chocolatey:
name: Update Chocolatey
if: github.event.client_payload.push-to-chocolatey && github.event.client_payload.version != ''
runs-on: windows-latest
steps:
- name: Ensure proper version
run: |
$workflow_version = "${{ github.event.inputs.version }}"
$repository_version = "${{ github.event.client_payload.version }}"
if (-not ([string]::IsNullOrEmpty($workflow_version))) {
$workflow_version = "$workflow_version" -replace 'v'
echo "RELEASE_VERSION=$workflow_version" | Out-File $env:GITHUB_ENV
exit 0
}
if (-not ([string]::IsNullOrEmpty($repository_version))) {
$repository_version = "$repository_version" -replace 'v'
echo "RELEASE_VERSION=($repository_version -replace 'v')" | Out-File $env:GITHUB_ENV
exit 0
}
Write-Host "Version not provided"
exit 1
$version = "${{ github.event.client_payload.version }}" -replace 'v'
echo "RELEASE_VERSION=$version" | Out-File $env:GITHUB_ENV
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
Expand All @@ -91,24 +64,13 @@ jobs:
push-to-winget:
name: Update Winget
if: github.event.client_payload.push-to-winget && github.event.client_payload.version != ''
runs-on: windows-latest
steps:
- name: Ensure proper version
run: |
$workflow_version = "${{ github.event.inputs.version }}"
$repository_version = "${{ github.event.client_payload.version }}"
if (-not ([string]::IsNullOrEmpty($workflow_version))) {
$workflow_version = "$workflow_version" -replace 'v'
echo "RELEASE_VERSION=$workflow_version" | Out-File $env:GITHUB_ENV
exit 0
}
if (-not ([string]::IsNullOrEmpty($repository_version))) {
$repository_version = "$repository_version" -replace 'v'
echo "RELEASE_VERSION=$repository_version" | Out-File $env:GITHUB_ENV
exit 0
}
Write-Host "Version not provided"
exit 1
$version = "${{ github.event.client_payload.version }}" -replace 'v'
echo "RELEASE_VERSION=$version" | Out-File $env:GITHUB_ENV
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
Expand Down
22 changes: 0 additions & 22 deletions .github/workflows/release-drafter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,6 @@ jobs:
go-version-file: '${{ github.workspace }}/go.mod'
cache: false

- name: Get go environment for use with cache
run: |
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
# This step will only reuse the go mod and build cache from main made during the Build,
# see push_ocm.yaml => "ocm-cli-latest" Job
# This means it never caches by itself and PRs cannot cause cache pollution / thrashing
# This is because we have huge storage requirements for our cache because of the mass of dependencies
- name: Restore / Reuse Cache from central build
id: cache-golang-restore
uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big)
with:
path: |
${{ env.go_cache }}
${{ env.go_modcache }}
key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }}
restore-keys: |
${{ env.cache_name }}-${{ runner.os }}-go-
env:
cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step

- name: Set Version
run: |
RELEASE_VERSION=v$(go run $GITHUB_WORKSPACE/api/version/generate print-version)
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,6 @@ jobs:
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ steps.generate_token.outputs.token }}
repository: open-component-model/ocm
event-type: ocm-cli-release
client-payload: '{"version": "${{ env.RELEASE_VERSION }}"}'
repository: ${{ github.repository_owner }}/ocm
event-type: publish-ocm-cli
client-payload: '{"version":"${{ env.RELEASE_VERSION }}","push-to-aur":true,"push-to-chocolatey":true,"push-to-winget":true}'
60 changes: 60 additions & 0 deletions .github/workflows/retrigger-publish-to-other.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Manually retrigger the publishing of ocm-cli to other repositories

on:
workflow_dispatch:
inputs:
version:
type: string
description: Which version (e.g. v0.42.0) do you want to publish?
required: true
default: ''
push-to-aur:
type: boolean
description: Do you want to push to the Arch Linux User Repository?
required: false
default: false
push-to-chocolatey:
type: boolean
description: Do you want to push to Chocolatey?
required: false
default: false
push-to-winget:
type: boolean
description: Do you want to push to Winget?
required: false
default: false

jobs:
retrigger:
name: Create new "Release Publish Event"
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
packages: write
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.OCMBOT_APP_ID }}
private_key: ${{ secrets.OCMBOT_PRIV_KEY }}
- name: Ensure proper version
run: |
curl -sSL -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ steps.generate_token.outputs.token }}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/open-component-model/ocm/releases > releases.json
jq -r '.[] | .tag_name' releases.json | grep -v -E '.*-rc|latest' > versions.txt
if grep -Fxq '${{ github.event.inputs.version }}' versions.txt; then
echo "Version (${{ github.event.inputs.version }}) found!"
else
echo "Version (${{ github.event.inputs.version }}) not found! This are the availble ones:"
cat versions.txt
exit 1
fi
echo "RELEASE_VERSION=$(echo ${{ github.event.inputs.version }} )" >> $GITHUB_ENV
- name: Publish Event
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ steps.generate_token.outputs.token }}
repository: ${{ github.repository_owner }}/ocm
event-type: publish-ocm-cli
client-payload: '{"version":"${{ env.RELEASE_VERSION }}","push-to-aur":${{ github.event.inputs.push-to-aur }},"push-to-chocolatey":${{ github.event.inputs.push-to-chocolatey }},"push-to-winget":${{ github.event.inputs.push-to-winget }}}'
8 changes: 4 additions & 4 deletions api/oci/art_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func CheckArt(ref string, exp *oci.ArtSpec) {
Expect(err).To(HaveOccurred())
} else {
Expect(err).To(Succeed())
Expect(spec).To(Equal(*exp))
Expect(spec).To(Equal(exp))
}
}

Expand All @@ -26,9 +26,9 @@ var _ = Describe("art parsing", func() {
It("succeeds", func() {
CheckArt("ubuntu", &oci.ArtSpec{Repository: "ubuntu"})
CheckArt("ubuntu/test", &oci.ArtSpec{Repository: "ubuntu/test"})
CheckArt("ubuntu/test@"+digest.String(), &oci.ArtSpec{Repository: "ubuntu/test", Digest: &digest})
CheckArt("ubuntu/test:"+tag, &oci.ArtSpec{Repository: "ubuntu/test", Tag: &tag})
CheckArt("ubuntu/test:"+tag+"@"+digest.String(), &oci.ArtSpec{Repository: "ubuntu/test", Digest: &digest, Tag: &tag})
CheckArt("ubuntu/test@"+digest.String(), &oci.ArtSpec{Repository: "ubuntu/test", ArtVersion: oci.ArtVersion{Digest: &digest}})
CheckArt("ubuntu/test:"+tag, &oci.ArtSpec{Repository: "ubuntu/test", ArtVersion: oci.ArtVersion{Tag: &tag}})
CheckArt("ubuntu/test:"+tag+"@"+digest.String(), &oci.ArtSpec{Repository: "ubuntu/test", ArtVersion: oci.ArtVersion{Digest: &digest, Tag: &tag}})
})

It("fails", func() {
Expand Down
10 changes: 8 additions & 2 deletions api/oci/extensions/repositories/artifactset/utils_synthesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"ocm.software/ocm/api/oci/artdesc"
"ocm.software/ocm/api/oci/cpi"
"ocm.software/ocm/api/oci/ociutils"
"ocm.software/ocm/api/oci/tools/transfer"
"ocm.software/ocm/api/oci/tools/transfer/filters"
"ocm.software/ocm/api/utils/accessio"
Expand Down Expand Up @@ -92,14 +93,19 @@ func SynthesizeArtifactBlobForArtifact(art cpi.ArtifactAccess, ref string, filte
return nil, err
}

vers, err := ociutils.ParseVersion(ref)
if err != nil {
return nil, err
}

return SythesizeArtifactSet(func(set *ArtifactSet) (string, error) {
dig, err := transfer.TransferArtifactWithFilter(art, set, filters.And(filter...))
if err != nil {
return "", fmt.Errorf("failed to transfer artifact: %w", err)
}

if ok, _ := artdesc.IsDigest(ref); !ok {
err = set.AddTags(*dig, ref)
if ok := vers.IsTagged(); ok {
err = set.AddTags(*dig, vers.GetTag())
if err != nil {
return "", fmt.Errorf("failed to add tag: %w", err)
}
Expand Down
97 changes: 97 additions & 0 deletions api/oci/ociutils/ref.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package ociutils

import (
"strings"

"github.com/mandelsoft/goutils/generics"
"github.com/opencontainers/go-digest"
)

// ParseVersion parses the version part of an OCI reference consisting
// of an optional tag and/or digest.
func ParseVersion(vers string) (*ArtVersion, error) {
if strings.HasPrefix(vers, "@") {
dig, err := digest.Parse(vers[1:])
if err != nil {
return nil, err
}
return &ArtVersion{
Digest: &dig,
}, nil
}

i := strings.Index(vers, "@")
if i > 0 {
dig, err := digest.Parse(vers[i+1:])
if err != nil {
return nil, err
}
return &ArtVersion{
Tag: generics.Pointer(vers[:i]),
Digest: &dig,
}, nil
}
return &ArtVersion{
Tag: &vers,
}, nil
}

// ArtVersion is the version part of an OCI reference consisting of an
// optional tag and/or digest. Both parts may be nil, if a reference
// does not include a version part.
// Such objects are sub objects of (oci.)ArtSpec, which has be moved
// to separate package to avoid package cycles. The methods are
// derived from ArtSpec.
type ArtVersion struct {
// +optional
Tag *string `json:"tag,omitempty"`
// +optional
Digest *digest.Digest `json:"digest,omitempty"`
}

func (v *ArtVersion) VersionSpec() string {
if v != nil {
return ""
}

vers := ""
if v.Tag != nil {
vers = *v.Tag
}

if v.Digest != nil {
vers += "@" + string(*v.Digest)
}
if vers == "" {
return "latest"
}
return vers
}

// IsVersion returns true, if the object ref is given
// and describes a dedicated version, either by tag or digest.
// As part of the ArtSpec type in oci, it might describe
// no version part. THis method indicates, whether a version part
// is present.
func (v *ArtVersion) IsVersion() bool {
if v == nil {
return false
}
return v.Tag != nil || v.Digest != nil
}

func (v *ArtVersion) IsTagged() bool {
return v != nil && v.Tag != nil
}

func (v *ArtVersion) IsDigested() bool {
return v != nil && v.Digest != nil
}

func (v *ArtVersion) GetTag() string {
if v != nil &&
v.Tag != nil {
return *v.Tag
}
return ""
}
Loading

0 comments on commit 4e55056

Please sign in to comment.