Skip to content

Commit 44265f7

Browse files
committed
add release templating + docs
1 parent 9a50fc4 commit 44265f7

File tree

11 files changed

+83
-38
lines changed

11 files changed

+83
-38
lines changed

.github/workflows/branchPR.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,3 @@ jobs:
7777
working-directory: out
7878
run: ls -la
7979

80-
- name: Check available assets
81-
if: hashFiles('out/awesome-ci_${{ needs.generate_infos.outputs.version }}_arm64') != '' || hashFiles('out/awesome-ci_${{ needs.generate_infos.outputs.version }}_amd64') != ''
82-
uses: actions/github-script@v3
83-
with:
84-
script: |
85-
core.setFailed('Not all files provided')

docs/commands/index.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@ awesome-ci <subcommand> [subcommand-option]
2929

3030
You can find out more about the subcommands by clicking on the relevant one in the navigation.
3131

32-
| Subcommand | Description |
33-
| ---------------------------------------------------------------------------------- | ------------------------------------------------------- |
34-
| [release](https://fullstack-devops.github.io/awesome-ci/commands/createRelease.html) | creates a release at GitHub or GitLab |
35-
| [pr](https://fullstack-devops.github.io/awesome-ci/commands/getBuildInfos.html) | prints out any git information and can manipulate these |
36-
| [parseJSON](https://fullstack-devops.github.io/awesome-ci/commands/parseJSON.html) | can parse simple JSON files |
37-
| [parseYAML](https://fullstack-devops.github.io/awesome-ci/commands/parseYAML.html) | can parse simple YAML files |
32+
| Subcommand | Description |
33+
| --------------------------------------- | ------------------------------------------|
34+
| [release](/commands/createRelease.html) | creates a release at GitHub or |
35+
| [pr](/commands/getBuildInfos.html) | prints out any git information and can manipulate |
36+
| [parseJSON](/commands/parseJSON.html) | can parse simple JSON |
37+
| [parseYAML](/commands/parseYAML.html) | can parse simple YAML files |
38+
39+
40+
## Release Body updates
41+
42+
Now available: Any string or any markdown file can now be attached in the release section. In addition, the release assets are attached as text to each release body with the associated sha256. More about that in the picture below and in the release section.
43+
44+
![Release Body with Asstes](/pictures/release-assets-readme.png "Release Body with Asstes")

docs/commands/release.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ awesome-ci release <subcommand> [subcommand-option]
2929
| `-version` | overrides any version from git and, or patches the given string |
3030
| `-patchLevel` | overrides the patchLevel. make shure your following the alias definition. |
3131
| `-dry-run` | doesn't create a release. Prints out what it would do and check permissions |
32+
| `-body` | add a text (markdown) to the release body |
3233
| `-assets` | (only available in publish) uploads the given Artifacts to a release. Eg.: `file=out/awesome-ci` |
3334
| `-releaseid` | (only available in publish) publishes an early defined release |
3435

@@ -42,15 +43,6 @@ This can be useful in connection with `-patchLevel` when creating a manual relea
4243
awesome-ci createRelease -version 0.1.0
4344
```
4445

45-
#### -patchLevel
46-
47-
The `-patchLevel` option can overwrite the evaluated patchLevel.
48-
This can be useful in connection with `-version` when creating a manual release.
49-
50-
```bash
51-
awesome-ci createRelease -patchLevel feature
52-
```
53-
5446
#### -assets
5547

5648
The `-assets` option can updload a single or multiple artifacts.
@@ -59,5 +51,10 @@ However, you must choose the format of the artefacts.
5951

6052
eg.: `-assets "file=path/to/file,file=path/to/second/file"`
6153

54+
#### -body
55+
56+
Send a custom release description. the input can be either a string or a path to a file.
57+
58+
![Release Body with Asstes](/pictures/release-assets-readme.png "Release Body with Asstes")
6259

6360
... more documentation to be done ;)
47.4 KB
Loading

release-template.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Awesome-CI
2+
3+
this project is still in the beta phase. But don't be shy and use this tool in advance. If you find bugs or have improvements, please feel free to open an [issue](https://github.com/fullstack-devops/awesome-ci/issues/new/choose) :rocket:

src/acigithub/release.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"os"
88
"strconv"
9+
"time"
910

1011
"github.com/google/go-github/v39/github"
1112
)
@@ -89,23 +90,16 @@ func PublishRelease(version string, body string, releaseId int64, uploadArtifact
8990
return err
9091
}
9192

92-
*existingRelease.Draft = draftFalse
93-
_, _, err = GithubClient.Repositories.EditRelease(
94-
ctx,
95-
owner,
96-
repo,
97-
releaseId,
98-
existingRelease)
99-
if err != nil {
100-
return err
101-
}
102-
93+
// upload any given artifacts
94+
var releaseBodyAssets string = ""
10395
if uploadArtifacts != nil {
10496
filesAndInfos, err := tools.GetAsstes(uploadArtifacts, false)
10597
if err != nil {
10698
return err
10799
}
108100

101+
releaseBodyAssets = "### Asstes\n"
102+
109103
for i, fileAndInfo := range filesAndInfos {
110104
fmt.Printf("uploading %s as asset to release\n", fileAndInfo.Name)
111105
// Upload assets to GitHub Release
@@ -121,6 +115,9 @@ func PublishRelease(version string, body string, releaseId int64, uploadArtifact
121115
if err != nil {
122116
log.Println("error at uploading asset to release: ", err)
123117
} else {
118+
// add asset to release body
119+
releaseBodyAssets = fmt.Sprintf("%s\n- [%s](%s) `%s`\n Sha256: `%x`", releaseBodyAssets, fileAndInfo.Name, *relAsset.BrowserDownloadURL, fileAndInfo.Infos.ModTime().Format(time.RFC3339), fileAndInfo.Hash)
120+
124121
// export Download URL to env. See: #53
125122
envVars, err := OpenEnvFile()
126123
if err != nil {
@@ -134,6 +131,22 @@ func PublishRelease(version string, body string, releaseId int64, uploadArtifact
134131
}
135132
}
136133
}
134+
135+
newReleaseBody := fmt.Sprintf("%s\n\n%s", *existingRelease.Body, releaseBodyAssets)
136+
existingRelease.Body = &newReleaseBody
137+
138+
// publishing release
139+
*existingRelease.Draft = draftFalse
140+
_, _, err = GithubClient.Repositories.EditRelease(
141+
ctx,
142+
owner,
143+
repo,
144+
releaseId,
145+
existingRelease)
146+
if err != nil {
147+
return err
148+
}
149+
137150
return
138151
}
139152

src/service/release.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ func ReleasePublish(args *ReleasePublishSet) {
102102
version = prInfos.NextVersion
103103
}
104104

105-
_, err = tools.GetAsstes(&args.Assets, true)
106-
if err != nil {
107-
log.Fatalln("not all specified asstes available, please check")
105+
if args.Assets != "" {
106+
_, err = tools.GetAsstes(&args.Assets, true)
107+
if err != nil {
108+
log.Fatalln("not all specified asstes available, please check")
109+
}
108110
}
109111

110112
if args.DryRun {

src/tools/files.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package tools
22

33
import (
4+
"crypto/sha256"
45
"fmt"
6+
"io"
7+
"io/fs"
58
"os"
69
"strings"
710
)
@@ -14,9 +17,12 @@ type UploadArtifact struct {
1417
type UploadAsset struct {
1518
File os.File
1619
Name string
20+
Infos fs.FileInfo
1721
IsZip bool
22+
Hash []byte
1823
}
1924

25+
// deprecated
2026
func GetFilesAndInfos(uploadArtifacts *string) (artifacts []UploadArtifact, err error) {
2127
artifactsToUpload := strings.Split(*uploadArtifacts, ",")
2228
for _, artifact := range artifactsToUpload {
@@ -56,10 +62,13 @@ func GetAsstes(uploadArtifacts *string, check bool) (asset []UploadAsset, err er
5662
if check {
5763
file.Close()
5864
} else {
65+
hash, _ := getHashFromFile(assetName[1])
5966
asset = append(asset, UploadAsset{
6067
File: *file,
6168
Name: info.Name(),
69+
Infos: info,
6270
IsZip: false,
71+
Hash: hash,
6372
})
6473
}
6574
case "files":
@@ -74,6 +83,21 @@ func GetAsstes(uploadArtifacts *string, check bool) (asset []UploadAsset, err er
7483
return
7584
}
7685

86+
func getHashFromFile(name string) (hash []byte, err error) {
87+
f, err := os.Open(name)
88+
if err != nil {
89+
return
90+
}
91+
defer f.Close()
92+
93+
h := sha256.New()
94+
if _, err = io.Copy(h, f); err != nil {
95+
return
96+
}
97+
98+
return h.Sum(nil), nil
99+
}
100+
77101
func CheckIsFile(name string) (body string, err error) {
78102
data, err := os.ReadFile(name)
79103
if err != nil {

tests/github_env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ ACI_VERSION=0.7.7
88
ACI_LATEST_VERSION=0.7.6
99
ACI_OWNER=fullstack-devops
1010
ACI_REPO=awesome-ci
11-
ACI_RELEASE_ID=58286218
11+
ACI_RELEASE_ID=58310269
1212
ACI_ARTIFACT_0_URL=https://github.com/eksrha/playground/releases/download/2.0.0/awesome-ci
1313
ACI_ARTIFACT_1_URL=https://github.com/eksrha/playground/releases/download/4.0.0/awesome-ci

tests/testdata/release.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Awesome-CI
2+
3+
This is a great readme to appear as the body of the release.
4+
5+
The great thing about it is that the asset section is self-generated by awesome-ci. However, only if an asset is also uploaded :rocket:

0 commit comments

Comments
 (0)