1414# dependency updates.
1515#
1616# You will also need to specify a value for the related commit message.
17+
1718name : Release
1819
1920on :
2021 workflow_dispatch :
2122 inputs :
22- versionLevel :
23- description : ' Version level (must be one of major, minor, patch) '
23+ newversion :
24+ description : ' Version level [ major | minor | patch | premajor | preminor | prepatch ] '
2425 required : true
2526 commitMessage :
26- description : ' Release/commit message'
27+ description : ' Release/commit message (%s will be replaced with the resulting version number) '
2728 required : true
2829
30+ env :
31+ REPORTS_DIR : CI_reports
32+ NODE_ACTIVE_LTS : " 16"
33+ DOCKERHUB_REPO : cyclonedx/cyclonedx-node
34+ ARTIFACT_DOCKER_SBOM : ' docker-image-bom'
35+
2936jobs :
30- release :
31- name : Release
37+ bump :
38+ outputs :
39+ version : ${{ steps.bump.outputs.version }}
40+ version_plain : ${{ steps.bump.outputs.version_plain }}
41+ name : bump and tag release
3242 runs-on : ubuntu-latest
3343 timeout-minutes : 30
34-
3544 steps :
36- 37-
38- - name : Setup Node.js
39- 40- with :
41- node-version : 12.x
45+ - name : Checkout code
46+ # see https://github.com/actions/checkout
47+ 48+ - name : Configure Git
49+ # needed for push back of changes
50+ run : |
51+ git config --local user.email "${GITHUB_ACTOR}@users.noreply.github.com"
52+ git config --local user.name "${GITHUB_ACTOR}"
53+ - name : Setup Node.js ${{ env.NODE_ACTIVE_LTS }}
54+ # see https://github.com/actions/setup-node
55+ 56+ with :
57+ node-version : ${{ env.NODE_ACTIVE_LTS }}
58+ # # ! no npm build at the moment
59+ - name : bump VERSION
60+ id : bump
61+ run : |
62+ VERSION="$(npm version "$NPMV_NEWVERSION" --message "$NPMV_MESSAGE")"
63+ echo "::debug::new version = $VERSION"
64+ VERSION_PLAIN="${VERSION:1}" # remove 'v' prefix
65+ echo "::debug::plain version = $VERSION_PLAIN"
66+ echo "::set-output name=version::$VERSION"
67+ echo "::set-output name=version_plain::$VERSION_PLAIN"
68+ env :
69+ NPMV_NEWVERSION : ${{ github.event.inputs.newversion }}
70+ NPMV_MESSAGE : ${{ github.event.inputs.commitMessage }}
71+ - name : git push back
72+ run : git push --follow-tags
4273
43- - name : Configure Git
44- run : |
45- git config --local user.email "${GITHUB_ACTOR}@users.noreply.github.com"
46- git config --local user.name "${GITHUB_ACTOR}"
74+ publish-NPM :
75+ needs :
76+ - " bump"
77+ name : NPM - publish
78+ runs-on : ubuntu-latest
79+ timeout-minutes : 30
80+ steps :
81+ - name : Checkout code
82+ # see https://github.com/actions/checkout
83+ 84+ with :
85+ ref : ${{ needs.bump.outputs.version }}
86+ - name : publish to NPM
87+ run : |
88+ npm config set "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN"
89+ npm publish --access public
90+ env :
91+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
4792
48- - name : Build & Publish
49- id : build
50- run : |
51- echo Version level: ${{ github.event.inputs.versionLevel }}
52- npm ci
53- npm run build --if-present
54- VERSION=$(npm version ${{ github.event.inputs.versionLevel }} --message "${{ github.event.inputs.commitMessage }}")
55- VERSION=${VERSION:1} # remove 'v' prefix
56- echo "##[set-output name=version;]$VERSION"
57- git push --follow-tags
58- npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
59- npm publish --access public
60- env :
61- NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
93+ release-DockerHub :
94+ needs :
95+ - " bump"
96+ name : DockerHub - build & publish
97+ runs-on : ubuntu-latest
98+ timeout-minutes : 30
99+ env :
100+ DI_VERSION : ${{ needs.bump.outputs.version_plain }}
101+ steps :
102+ - name : Checkout code
103+ # see https://github.com/actions/checkout
104+ 105+ with :
106+ ref : ${{ needs.bump.outputs.version }}
107+ - name : Login to DockerHub
108+ run : docker login --username "$DOCKERHUB_USERNAME" --password "$DOCKERHUB_TOKEN"
109+ env :
110+ DOCKERHUB_USERNAME : ${{ secrets.DOCKERHUB_USERNAME }}
111+ DOCKERHUB_TOKEN : ${{ secrets.DOCKERHUB_TOKEN }}
112+ - name : build Docker image
113+ run : >
114+ docker build
115+ -t "$DOCKERHUB_REPO:$DI_VERSION"
116+ -t "$DOCKERHUB_REPO:latest"
117+ -f Dockerfile .
118+ - name : fetch own SBOM
119+ run : |
120+ mkdir "$REPORTS_DIR"
121+ docker run --rm \
122+ -v "$PWD/$REPORTS_DIR:/src/$REPORTS_DIR" \
123+ "$DOCKERHUB_REPO:$DI_VERSION" \
124+ --type 'application' \
125+ --output "/src/$REPORTS_DIR/docker-image.bom.xml"
126+ docker run --rm \
127+ -v "$PWD/$REPORTS_DIR:/src/$REPORTS_DIR" \
128+ "$DOCKERHUB_REPO:$DI_VERSION" \
129+ --type 'application' \
130+ --output "/src/$REPORTS_DIR/docker-image.bom.json"
131+ - name : Artifact reports
132+ if : ${{ ! cancelled() }}
133+ # see https://github.com/actions/upload-artifact
134+ uses : actions/upload-artifact@v2
135+ with :
136+ name : ${{ env.ARTIFACT_DOCKER_SBOM }}
137+ path : ${{ env.REPORTS_DIR }}
138+ if-no-files-found : error
139+ - name : publish Docker image
140+ run : docker push "$DOCKERHUB_REPO:$DI_VERSION"
141+ - name : publish latest Docker image
142+ if : ${{ ! startsWith(github.event.inputs.newversion, 'pre') }}
143+ run : docker push "$DOCKERHUB_REPO:latest"
144+ - name : Destroy Docker image
145+ # run regardless of outcome
146+ if : ${{ always() }}
147+ run : >
148+ docker rmi -f
149+ "$DOCKERHUB_REPO:$DI_VERSION"
150+ "$DOCKERHUB_REPO:latest"
62151
63- - name : Publish Docker image to Docker Hub
64- env :
65- DOCKERHUB_USERNAME : ${{ secrets.DOCKERHUB_USERNAME }}
66- DOCKERHUB_TOKEN : ${{ secrets.DOCKERHUB_TOKEN }}
67- run : |
68- REPO=cyclonedx/cyclonedx-node
69- VERSION=${{ steps.build.outputs.version }}
70- docker login --username $DOCKERHUB_USERNAME --password "$DOCKERHUB_TOKEN"
71- docker build -f Dockerfile -t $REPO:$VERSION -t $REPO:latest .
72- docker push $REPO:latest
73- docker push $REPO:$VERSION
152+ release-GH :
153+ needs :
154+ - " bump"
155+ - " publish-NPM"
156+ - " release-DockerHub"
157+ name : GitHub - release
158+ runs-on : ubuntu-latest
159+ timeout-minutes : 30
160+ env :
161+ ASSETS_DIR : release_assets
162+ steps :
163+ - name : create assets dir
164+ run : mkdir "$ASSETS_DIR"
165+ - name : download docker image sboms
166+ # see https://github.com/actions/download-artifact
167+ uses : actions/download-artifact@v2
168+ with :
169+ name : ${{ env.ARTIFACT_DOCKER_SBOM }}
170+ path : ${{ env.ASSETS_DIR }}/${{ env.ARTIFACT_DOCKER_SBOM }}
171+ - name : Create Release
172+ id : release
173+ # see https://github.com/softprops/action-gh-release
174+ uses : softprops/action-gh-release@v1
175+ env :
176+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
177+ with :
178+ tag_name : ${{ needs.bump.outputs.version }}
179+ name : ${{ needs.bump.outputs.version_plain }}
180+ prerelease : ${{ startsWith(github.event.inputs.newversion, 'pre') }}
181+ files : |
182+ ${{ env.ASSETS_DIR }}/${{ env.ARTIFACT_DOCKER_SBOM }}/*.bom.*
0 commit comments