Skip to content

Commit

Permalink
Merge branch 'release-2.12' of github.com:codefresh-io/argo-cd into C…
Browse files Browse the repository at this point in the history
…R-23668-refactoring
  • Loading branch information
oleksandr-codefresh committed Oct 25, 2024
2 parents 35bdffa + 8e77c57 commit 98e180d
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 29 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/cf-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Init CF ArgoCD Release
on:
workflow_dispatch:

permissions:
contents: write
actions: write

jobs:
prepare-release:
permissions:
contents: write
actions: write # for peter-evans/create-pull-request to create branch
name: Automatically generate version and manifests on ${{ inputs.TARGET_BRANCH }}
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@8410ad0602e1e429cee44a835ae9f77f654a6694 # v4.0.0
with:
fetch-depth: 0
# use personal token due to https://stackoverflow.com/questions/72110432/github-workflow-is-not-triggered-after-pushing-tags
token: ${{ secrets.RELEASE_GITHUB_TOKEN }}
ref: ${{ inputs.TARGET_BRANCH }}

- name: Check if TARGET_VERSION is well formed.
run: |
set -xue
# Target version must not contain 'v' prefix
if echo "${{ inputs.TARGET_VERSION }}" | grep -e '^v'; then
echo "::error::Target version '${{ inputs.TARGET_VERSION }}' should not begin with a 'v' prefix, refusing to continue." >&2
exit 1
fi
- name: Create release
run: |
git config --global user.name "CI-Codefresh"
git config --global user.email "[email protected]"
make cf-release
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Create ArgoCD release
on:
push:
tags:
- "release-v*"
- "release-v**"
- "!release-v1.5*"
- "!release-v1.4*"
- "!release-v1.3*"
Expand Down
1 change: 1 addition & 0 deletions SOURCE_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.12.3
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.12-2024.10.23-0c500acc9
2.12.3-2024.10.24-d2f4245b5
17 changes: 9 additions & 8 deletions acr_controller/service/acr_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package service
import (
"context"
"encoding/json"
"errors"
"sync"

log "github.com/sirupsen/logrus"
Expand All @@ -25,12 +24,14 @@ type acrService struct {
applicationClientset appclientset.Interface
applicationServiceClient argoclient.ApplicationClient
lock sync.Mutex
logger *log.Logger
}

func NewACRService(applicationClientset appclientset.Interface, applicationServiceClient argoclient.ApplicationClient) ACRService {
return &acrService{
applicationClientset: applicationClientset,
applicationServiceClient: applicationServiceClient,
logger: log.New(),
}
}

Expand Down Expand Up @@ -68,8 +69,8 @@ func (c *acrService) ChangeRevision(ctx context.Context, a *application.Applicat
}

if getChangeRevision(app) != "" {
log.Infof("Change revision already calculated for application %s", app.Name)
return errors.New("change revision already calculated")
c.logger.Infof("Change revision already calculated for application %s", app.Name)
return nil
}

revision, err := c.calculateRevision(ctx, app)
Expand All @@ -78,11 +79,11 @@ func (c *acrService) ChangeRevision(ctx context.Context, a *application.Applicat
}

if revision == nil || *revision == "" {
log.Infof("Revision for application %s is empty", app.Name)
c.logger.Infof("Revision for application %s is empty", app.Name)
return nil
}

log.Infof("Change revision for application %s is %s", app.Name, *revision)
c.logger.Infof("Change revision for application %s is %s", app.Name, *revision)

app, err = c.applicationClientset.ArgoprojV1alpha1().Applications(app.Namespace).Get(ctx, app.Name, metav1.GetOptions{})
if err != nil {
Expand All @@ -92,17 +93,17 @@ func (c *acrService) ChangeRevision(ctx context.Context, a *application.Applicat
revisions := []string{*revision}

if app.Status.OperationState != nil && app.Status.OperationState.Operation.Sync != nil {
log.Infof("Patch operation sync result for application %s", app.Name)
c.logger.Infof("Patch operation sync result for application %s", app.Name)
return c.patchOperationSyncResultWithChangeRevision(ctx, app, revisions)
}

log.Infof("Patch operation for application %s", app.Name)
c.logger.Infof("Patch operation for application %s", app.Name)
return c.patchOperationWithChangeRevision(ctx, app, revisions)
}

func (c *acrService) calculateRevision(ctx context.Context, a *application.Application) (*string, error) {
currentRevision, previousRevision := c.getRevisions(ctx, a)
log.Infof("Calculate revision for application '%s', current revision '%s', previous revision '%s'", a.Name, currentRevision, previousRevision)
c.logger.Infof("Calculate revision for application '%s', current revision '%s', previous revision '%s'", a.Name, currentRevision, previousRevision)
changeRevisionResult, err := c.applicationServiceClient.GetChangeRevision(ctx, &appclient.ChangeRevisionRequest{
AppName: pointer.String(a.GetName()),
Namespace: pointer.String(a.GetNamespace()),
Expand Down
19 changes: 18 additions & 1 deletion acr_controller/service/acr_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"context"
"testing"

"github.com/sirupsen/logrus"
test2 "github.com/sirupsen/logrus/hooks/test"

"github.com/argoproj/argo-cd/v2/acr_controller/application/mocks"
appclient "github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
appsv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
Expand Down Expand Up @@ -207,6 +210,7 @@ func newTestACRService(client *mocks.ApplicationClient) *acrService {
return &acrService{
applicationClientset: fakeAppsClientset,
applicationServiceClient: client,
logger: logrus.New(),
}
}

Expand Down Expand Up @@ -285,7 +289,12 @@ func Test_ChangeRevision(r *testing.T) {
client.On("GetChangeRevision", mock.Anything, mock.Anything).Return(&appclient.ChangeRevisionResponse{
Revision: pointer.String("new-revision"),
}, nil)

logger, logHook := test2.NewNullLogger()

acrService := newTestACRService(client)
acrService.logger = logger

app := createTestApp(syncedAppWithHistory)

err := acrService.ChangeRevision(context.TODO(), app)
Expand All @@ -297,6 +306,14 @@ func Test_ChangeRevision(r *testing.T) {
assert.Equal(t, "new-revision", app.Status.OperationState.Operation.Sync.ChangeRevision)

err = acrService.ChangeRevision(context.TODO(), app)
require.Error(t, err, "change revision already calculated")

require.NoError(t, err)

lastLogEntry := logHook.LastEntry()
if lastLogEntry == nil {
t.Fatal("No log entry")
}

require.Equal(t, "Change revision already calculated for application guestbook", lastLogEntry.Message)
})
}
2 changes: 2 additions & 0 deletions changelog/CHANGELOG-2.12.3-2024.10.24-01773faa9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Features
- chore: new release lifecycle
2 changes: 2 additions & 0 deletions changelog/CHANGELOG-2.12.3-2024.10.24-17b898fc3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Features
- chore: new release lifecycle
2 changes: 2 additions & 0 deletions changelog/CHANGELOG-2.12.3-2024.10.24-2818781ba.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Features
- chore: new release lifecycle
2 changes: 2 additions & 0 deletions changelog/CHANGELOG-2.12.3-2024.10.24-4245c5379.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Features
- chore: new release lifecycle
2 changes: 2 additions & 0 deletions changelog/CHANGELOG-2.12.3-2024.10.24-477675894.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Features
- chore: new release lifecycle
2 changes: 2 additions & 0 deletions changelog/CHANGELOG-2.12.3-2024.10.24-5204e2b0e.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Features
- chore: new release lifecycle
2 changes: 2 additions & 0 deletions changelog/CHANGELOG-2.12.3-2024.10.24-531413858.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Features
- chore: new release lifecycle
2 changes: 2 additions & 0 deletions changelog/CHANGELOG-2.12.3-2024.10.24-7419c42e2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Features
- chore: new release lifecycle
2 changes: 2 additions & 0 deletions changelog/CHANGELOG-2.12.3-2024.10.24-a9323b2b4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Features
- chore: new release lifecycle
2 changes: 2 additions & 0 deletions changelog/CHANGELOG-2.12.3-2024.10.24-ac70e7594.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Features
- chore: new release lifecycle
2 changes: 2 additions & 0 deletions changelog/CHANGELOG-2.12.3-2024.10.24-bad5d67c0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Features
- chore: new release lifecycle
2 changes: 2 additions & 0 deletions changelog/CHANGELOG-2.12.3-2024.10.24-d2f4245b5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Features
- chore: new release lifecycle
2 changes: 2 additions & 0 deletions changelog/CHANGELOG-2.12.3-2024.10.24-f6464d0db.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Features
- chore: new release lifecycle
2 changes: 1 addition & 1 deletion changelog/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
### Features
- feat(event-reporter): added warning conditions reporting
- chore: new release lifecycle
28 changes: 11 additions & 17 deletions hack/release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"os/exec"
"regexp"
"strings"
"time"
)
Expand All @@ -29,21 +28,11 @@ func getCurrentCommitSha() (string, error) {
}

func getArgoCDVersion() (string, error) {
// git rev-parse --abbrev-ref HEAD
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
result, err := cmd.Output()
data, err := os.ReadFile("SOURCE_VERSION")
if err != nil {
return "", err
}

pattern := `release-(\d+\.\d+)`
re := regexp.MustCompile(pattern)
matches := re.FindStringSubmatch(string(result))
if len(matches) >= 2 {
return matches[1], nil
}

return "", fmt.Errorf("failed to get argocd version")
return strings.TrimSpace(string(data)), nil
}

// function that returns version of the latest release by patern
Expand Down Expand Up @@ -94,7 +83,7 @@ func moveChangelog() error {
}

// mv changelog/CHANGELOG.md changelog/CHANGELOG-<version>.md
cmd := exec.Command("mv", "changelog/CHANGELOG.md", fmt.Sprintf("changelog/CHANGELOG-%s.md", version))
cmd := exec.Command("cp", "changelog/CHANGELOG.md", fmt.Sprintf("changelog/CHANGELOG-%s.md", version))
if output, err := cmd.CombinedOutput(); err != nil {
fmt.Print(string(output))
return err
Expand Down Expand Up @@ -127,12 +116,12 @@ func release() error {
if err != nil {
return err
}

fmt.Println("Commit changes")
err = commitChanges(version)
if err != nil {
return err
}

fmt.Println("Create tag")
// git tag -a v2.9.3-2021.07.07-3a4b7f4 -m "Codefresh version for synced 2.9.3"
_ = exec.Command("git", "tag", "-d", release).Run()
cmd := exec.Command("git", "tag", "-a", release, "-m", changelog)
Expand All @@ -141,15 +130,20 @@ func release() error {
return fmt.Errorf("failed to tag: %w", err)
}

fmt.Println("Delete tag")
// git push remote-name --delete tag-name
_ = exec.Command("git", "push", "origin", "--delete", release).Run()
fmt.Println("Push new tag to remote")
// git push origin tags/version
cmd = exec.Command("git", "push", "origin", "tags/"+release)
if output, err := cmd.CombinedOutput(); err != nil {
output, err := cmd.CombinedOutput()
if err != nil {
fmt.Print(string(output))
return fmt.Errorf("failed to push tag: %w", err)
}
fmt.Printf("git push output: %s\n", string(output))

fmt.Println("Delete tag from remote")
return exec.Command("git", "push", "origin", "--delete", release).Run()
}

Expand Down

0 comments on commit 98e180d

Please sign in to comment.