@@ -60,10 +60,10 @@ func fileExists(params *Param) bool {
6060
6161}
6262
63- func createFile (params * Param ) {
63+ func createFile (params * Param ) ( bool , error ) {
6464 if fileExists (params ) {
6565 log .Printf ("github actions workflow %s already exists\n " , params .workflow .workflowFileName )
66- return
66+ return true , nil
6767 }
6868
6969 // Note: the file needs to be absent from the repository as you are not
@@ -83,8 +83,39 @@ func createFile(params *Param) {
8383 opts )
8484
8585 if err != nil {
86- fmt .Println (err .Error ())
87- return
86+ log .Println (err .Error ())
87+ return false , err
8888 }
8989 log .Printf ("github actions workflow %s created\n " , params .workflow .workflowFileName )
90+ return true , nil
91+ }
92+
93+ func removeFile (params * Param ) (bool , error ) {
94+ if ! fileExists (params ) {
95+ log .Printf ("github actions workflow %s already removed\n " , params .workflow .workflowFileName )
96+ return true , nil
97+ }
98+
99+ // Note: the file needs to be absent from the repository as you are not
100+ // specifying a SHA reference here.
101+ opts := & github.RepositoryContentFileOptions {
102+ Message : github .String (params .workflow .commitMessage ),
103+ Content : []byte (params .workflow .workflowContent ),
104+ Branch : github .String ("master" ),
105+ }
106+
107+ log .Printf ("deleting github actions workflow %s...\n " , params .workflow .workflowFileName )
108+ _ , _ , err := params .client .Repositories .DeleteFile (
109+ * params .ctx ,
110+ params .options .Owner ,
111+ params .options .Repo ,
112+ generateGitHubWorkflowFileByName (params .workflow .workflowFileName ),
113+ opts )
114+
115+ if err != nil {
116+ log .Println (err .Error ())
117+ return false , err
118+ }
119+ log .Printf ("github actions workflow %s removed\n " , params .workflow .workflowFileName )
120+ return true , nil
90121}
0 commit comments