|
|
@@ -75,12 +75,13 @@ func (g *GithubActions) Setup() (string, error) {
|
|
|
return "", err
|
|
|
}
|
|
|
|
|
|
- return g.commitGithubFile(client, fileBytes)
|
|
|
+ return g.commitGithubFile(client, g.getPorterYMLFileName(), fileBytes)
|
|
|
}
|
|
|
|
|
|
type GithubActionYAMLStep struct {
|
|
|
Name string `yaml:"name"`
|
|
|
ID string `yaml:"id"`
|
|
|
+ Uses string `yaml:"uses"`
|
|
|
Run string `yaml:"run"`
|
|
|
}
|
|
|
|
|
|
@@ -119,6 +120,7 @@ func (g *GithubActions) GetGithubActionYAML() ([]byte, error) {
|
|
|
"porter-deploy": GithubActionYAMLJob{
|
|
|
RunsOn: "ubuntu-latest",
|
|
|
Steps: []GithubActionYAMLStep{
|
|
|
+ getCheckoutCodeStep(),
|
|
|
getDownloadPorterStep(),
|
|
|
getConfigurePorterStep(g.getPorterTokenSecretName()),
|
|
|
getDockerBuildPushStep(g.DockerFilePath, g.ImageRepoURL),
|
|
|
@@ -199,18 +201,25 @@ func (g *GithubActions) getWebhookSecretName() string {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+func (g *GithubActions) getPorterYMLFileName() string {
|
|
|
+ return fmt.Sprintf("porter_%s.yml", strings.Replace(
|
|
|
+ strings.ToLower(g.ReleaseName), "-", "_", -1),
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
func (g *GithubActions) getPorterTokenSecretName() string {
|
|
|
return fmt.Sprintf("PORTER_TOKEN_%d", g.ProjectID)
|
|
|
}
|
|
|
|
|
|
func (g *GithubActions) commitGithubFile(
|
|
|
client *github.Client,
|
|
|
+ filename string,
|
|
|
contents []byte,
|
|
|
) (string, error) {
|
|
|
- fmt.Println("GITHUB ACTION CONTENTS ARE", string(contents))
|
|
|
+ filepath := ".github/workflows/" + filename
|
|
|
|
|
|
opts := &github.RepositoryContentFileOptions{
|
|
|
- Message: github.String("Create porter.yml file"),
|
|
|
+ Message: github.String(fmt.Sprintf("Create %s file", filename)),
|
|
|
Content: contents,
|
|
|
Branch: github.String(g.defaultBranch),
|
|
|
Committer: &github.CommitAuthor{
|
|
|
@@ -219,11 +228,11 @@ func (g *GithubActions) commitGithubFile(
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- resp, _, err := client.Repositories.CreateFile(
|
|
|
+ resp, _, err := client.Repositories.UpdateFile(
|
|
|
context.TODO(),
|
|
|
g.GitRepoOwner,
|
|
|
g.GitRepoName,
|
|
|
- ".github/workflows/porter.yml",
|
|
|
+ filepath,
|
|
|
opts,
|
|
|
)
|
|
|
|