Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor git-push-service action #1767

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

int128
Copy link
Member

@int128 int128 commented Jan 7, 2025

This will apply the refactoring. There is no specification change.

Comment on lines +43 to +48
annotations: {
...parseApplicationAnnotations(inputs.applicationAnnotations),
'github.ref': inputs.currentRef,
'github.sha': inputs.currentSha,
'github.action': 'git-push-service',
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from:

const applicationAnnotations = [
...inputs.applicationAnnotations,
`github.ref=${github.context.ref}`,
`github.sha=${github.context.sha}`,
`github.action=git-push-service`,
]

core.info(`writing to ${destination}`)
const content = generateApplicationManifest(application)
await fs.writeFile(destination, content)
const parseApplicationAnnotations = (applicationAnnotations: string[]): Record<string, string> => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from:

if (a.annotations.length > 0) {
const annotations: { [_: string]: string } = {}
for (const s of a.annotations) {
const k = s.substring(0, s.indexOf('='))
const v = s.substring(s.indexOf('=') + 1)
annotations[k] = v
}
application.metadata.annotations = annotations
}

Comment on lines +36 to +67
const application = {
apiVersion: 'argoproj.io/v1alpha1',
kind: 'Application',
metadata: {
name: `${inputs.namespace}--${inputs.service}`,
namespace: 'argocd',
finalizers: ['resources-finalizer.argocd.argoproj.io'],
annotations: {
...parseApplicationAnnotations(inputs.applicationAnnotations),
'github.ref': inputs.currentRef,
'github.sha': inputs.currentSha,
'github.action': 'git-push-service',
},
},
spec: {
project: inputs.project,
source: {
repository: inputs.destinationRepository,
branch: inputs.branch,
repoURL: `https://github.com/${inputs.destinationRepository}.git`,
targetRevision: inputs.branch,
path: `services/${inputs.service}`,
},
destination: {
server: `https://kubernetes.default.svc`,
namespace: inputs.namespace,
},
annotations: inputs.applicationAnnotations,
syncPolicy: {
automated: {
prune: true,
},
},
},
inputs.workspace,
)
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from:

const application: KubernetesApplication = {
apiVersion: 'argoproj.io/v1alpha1',
kind: 'Application',
metadata: {
name: a.name,
namespace: 'argocd',
finalizers: ['resources-finalizer.argocd.argoproj.io'],
},
spec: {
project: a.project,
source: {
repoURL: `https://github.com/${a.source.repository}.git`,
targetRevision: a.source.branch,
path: a.source.path,
},
destination: {
server: `https://kubernetes.default.svc`,
namespace: a.destination.namespace,
},
syncPolicy: {
automated: {
prune: true,
},
},
},
}

}

export const arrangeManifests = async (inputs: Inputs): Promise<void> => {
return await arrangeServiceManifests(inputs)
export const writeManifests = async (inputs: Inputs): Promise<void> => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename the functions to write prefix.

@int128 int128 marked this pull request as ready for review January 7, 2025 02:08
@int128 int128 requested review from 44smkn and a team January 7, 2025 02:13
Copy link

@44smkn 44smkn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel readability became better than before :lgtm:

@int128 int128 merged commit 17e319f into main Jan 7, 2025
3 checks passed
@int128 int128 deleted the int128/Refactor-git-push-service-action branch January 7, 2025 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants