Skip to content

Commit 6be752c

Browse files
authored
Merge pull request #84 from maysunfaisal/makeRelease-1
Add release changelog generator
2 parents f3024dd + 48f5fd7 commit 6be752c

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ main
2424
# File created running tests
2525
tests/**/tmp/
2626

27+
# Mac related files
2728
.DS_Store
29+
30+
# Release utility changelog files
31+
CHANGELOG.md

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ The function documentation can be accessed via [pkg.go.dev](https://pkg.go.dev/g
6565

6666
## Updating Library Schema
6767

68-
Run `updateApi.sh` can update to use latest `github.com/devfile/api` and update the schema saved under `pkg/devfile/parser/data`
68+
Executing `./scripts/updateApi.sh` fetches the latest `github.com/devfile/api` go mod and updates the schema saved under `pkg/devfile/parser/data`
6969

70-
The script also accepts version number as an argument to update devfile schema for a specific devfile version.
71-
For example, run the following command will update devfile schema for 2.0.0
70+
The script also accepts a version number as an argument to update the devfile schema for a specific devfile version.
71+
For example, running the following command will update the devfile schema for 2.0.0
7272
```
7373
./updateApi.sh 2.0.0
7474
```
75-
Running the script with no arguments will default to update the latest devfile version
75+
Running the script with no arguments will default to update the latest devfile version.
7676

7777
## Projects using devfile/library
7878

@@ -90,3 +90,5 @@ Issues are tracked in the [devfile/api](https://github.com/devfile/api) repo wit
9090
## Releases
9191

9292
For devfile/library releases, please check the release [page](https://github.com/devfile/library/releases).
93+
94+
Note: To generate a changelog for a new release, execute `./scripts/changelog-script.sh v1.x.y` for all the changes since the release v1.x.y

scripts/changelog-script.sh

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
#!/bin/bash
3+
4+
# This script uses github_changelog_generator to generate a changelog and requires:
5+
#
6+
# 1. set an env GITHUB_TOKEN for the Github token
7+
# 2. previous release as an arg, to generate changelog since the mentioned release
8+
# 3. github_changelog_generator be installed where the script is being executed
9+
#
10+
# A CHANGELOG.md is generated and it's contents can be copy-pasted on the Github release
11+
12+
#TODO: Since issue tracking happens in devfile/api, github_changelog_generator cannot
13+
# detect the issues from a different repository. Need to check if this is achievable.
14+
15+
BLUE='\033[1;34m'
16+
GREEN='\033[0;32m'
17+
RED='\033[0;31m'
18+
NC='\033[0m'
19+
BOLD='\033[1m'
20+
21+
# Ensure the github token is set
22+
if [ -z "$GITHUB_TOKEN" ]
23+
then
24+
echo -e "${RED}GITHUB_TOKEN env variable is empty..\nGet your GitHub token from https://github.com/settings/tokens and export GITHUB_TOKEN=<token>${NC}"
25+
exit 1
26+
fi
27+
28+
# Ensure there is a release version passed in
29+
if [ -z "$1" ]
30+
then
31+
echo -e "${RED}The last release version needs to be provided. Changelog will be generated since that release..${NC}"
32+
echo -e "${RED}Example: ./changelog-script.sh v1.0.0-alpha.2 will generate a changelog for all the changes since release v1.0.0-alpha.2${NC}"
33+
exit 1
34+
fi
35+
36+
# Ensure github_changelog_generator is installed
37+
if ! command -v github_changelog_generator &> /dev/null
38+
then
39+
echo -e "${RED}The command github_changelog_generator could not be found, please install the command to generate a changelog${NC}"
40+
exit 1
41+
fi
42+
43+
44+
github_changelog_generator \
45+
-u devfile \
46+
-p library \
47+
-t $GITHUB_TOKEN \
48+
--since-tag $1 \
49+
50+
RESULT=$?
51+
52+
if [ $RESULT -eq 0 ]; then
53+
echo -e "${GREEN}Changelog since release $1 generated at $PWD/CHANGELOG.md${NC}"
54+
else
55+
echo -e "${RED}Unable to generate changelog using github_changelog_generator${NC}"
56+
exit 1
57+
fi

updateApi.sh scripts/updateApi.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ BOLD='\033[1m'
88

99
set -e
1010

11+
DIR=$(dirname $0)
1112
CURRENT_DIR=$(pwd)
1213
API_PKG="github.com/devfile/api/v2"
1314
SCHEMA_URL_MASTER="https://raw.githubusercontent.com/devfile/api/main/schemas/latest/devfile.json"
@@ -16,12 +17,12 @@ SCHEMA_URL_MASTER="https://raw.githubusercontent.com/devfile/api/main/schemas/la
1617
SCHEMA_URL_200="https://raw.githubusercontent.com/devfile/api/2.0.x/schemas/latest/devfile.json"
1718
PACKAGE_VERSION_200="version200"
1819
JSON_SCHEMA_200="JsonSchema200"
19-
FILE_PATH_200="./pkg/devfile/parser/data/v2/2.0.0/devfileJsonSchema200.go"
20+
FILE_PATH_200="$DIR/../pkg/devfile/parser/data/v2/2.0.0/devfileJsonSchema200.go"
2021

2122
# 2.1.0 devfile
2223
PACKAGE_VERSION_210="version210"
2324
JSON_SCHEMA_210="JsonSchema210"
24-
FILE_PATH_210="./pkg/devfile/parser/data/v2/2.1.0/devfileJsonSchema210.go"
25+
FILE_PATH_210="$DIR/../pkg/devfile/parser/data/v2/2.1.0/devfileJsonSchema210.go"
2526

2627

2728
onError() {
@@ -55,5 +56,5 @@ schema=$(curl -L "${SCHEMA_URL}")
5556

5657
#replace all ` with ' and write to schema file
5758
echo -e "${GREEN}Write to go file${NC}"
58-
go build *.go
59+
go build $DIR/../*.go
5960
./main updateSchema "${schema}" "${SCHEMA_URL}" "${PACKAGE_VERSION}" "${JSON_SCHEMA}" "${FILE_PATH}"

0 commit comments

Comments
 (0)