Skip to content

Commit 70ee40a

Browse files
authored
GH-action: split release to npm, dockerhub, github
Merge pull request #223 from CycloneDX/gh-release
2 parents b71803d + 584842b commit 70ee40a

File tree

4 files changed

+199
-53
lines changed

4 files changed

+199
-53
lines changed

.dockerignore

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
.dockerignore
2+
Dockerfile
3+
4+
## node specifics
25
node_modules
36
npm-debug.log
4-
Dockerfile
7+
8+
# repo specifics
59
.git
6-
.gitignore
10+
.gitignore
11+
12+
# reports
13+
reports
14+
CI_REPORTS

.github/workflows/docker.yml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,51 @@ on:
99
pull_request:
1010
workflow_dispatch:
1111

12+
env:
13+
REPORTS_DIR: CI_reports
14+
NODE_ACTIVE_LTS: "16"
15+
1216
jobs:
1317
test:
1418
name: Build and test docker image
1519
runs-on: ubuntu-latest
1620
timeout-minutes: 30
1721
env:
22+
REPORTS_ARTIFACT: 'docker-image-bom'
1823
DOCKER_TAG: 'cdx-node-module-testing:${{ github.run_id }}.${{ github.run_number }}.${{ github.run_attempt }}'
1924
steps:
2025
- name: Checkout
2126
# see https://github.com/actions/checkout
2227
uses: actions/[email protected]
28+
- name: Login to DockerHub
29+
run: docker login --username "$DOCKERHUB_USERNAME" --password "$DOCKERHUB_TOKEN"
30+
env:
31+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
32+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
33+
## ! no npm build at the moment
2334
- name: Build Docker image
24-
run: docker build -f Dockerfile -t "$DOCKER_TAG" .
25-
- name: Test Docker image
26-
run: docker run --rm "$DOCKER_TAG" -h
35+
run: docker build -t "$DOCKER_TAG" -f Dockerfile .
36+
- name: 'Test: fetch own SBOM'
37+
run: |
38+
mkdir "$REPORTS_DIR"
39+
docker run --rm \
40+
-v "$PWD/$REPORTS_DIR:/src/$REPORTS_DIR" \
41+
"$DOCKER_TAG" \
42+
--type 'application' \
43+
--output "/src/$REPORTS_DIR/docker-image.bom.xml"
44+
docker run --rm \
45+
-v "$PWD/$REPORTS_DIR:/src/$REPORTS_DIR" \
46+
"$DOCKER_TAG" \
47+
--type 'application' \
48+
--output "/src/$REPORTS_DIR/docker-image.bom.json"
49+
- name: Artifact reports
50+
if: ${{ ! cancelled() }}
51+
# see https://github.com/actions/upload-artifact
52+
uses: actions/upload-artifact@v2
53+
with:
54+
name: ${{ env.REPORTS_ARTIFACT }}
55+
path: ${{ env.REPORTS_DIR }}
56+
if-no-files-found: error
2757
- name: Destroy Docker image
2858
# run regardless of outcome
2959
if: ${{ always() }}

.github/workflows/nodejs.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ on:
1111

1212

1313
env:
14-
CI: "true"
1514
REPORTS_DIR: CI_reports
15+
NODE_ACTIVE_LTS: "16"
1616

1717
jobs:
1818
unit-test:
@@ -38,7 +38,7 @@ jobs:
3838
- name: dir setup
3939
run: mkdir ${{ env.REPORTS_DIR }}
4040
- name: Setup Node.js ${{ matrix.node-version }}
41-
## see https://github.com/actions/setup-node
41+
# see https://github.com/actions/setup-node
4242
uses: actions/[email protected]
4343
with:
4444
node-version: ${{ matrix.node-version }}
@@ -66,8 +66,7 @@ jobs:
6666
## see https://www.npmjs.com/package/jest-junit
6767
JEST_JUNIT_OUTPUT_DIR: ${{ env.REPORTS_DIR }}/${{ matrix.os }}_${{ matrix.node-version }}
6868
JEST_JUNIT_OUTPUT_NAME: junit.xml
69-
- name: try to buil project
70-
run: npm run build --if-present
69+
## ! no npm build at the moment
7170
- name: Artifact reports
7271
if: ${{ ! cancelled() }}
7372
# see https://github.com/actions/upload-artifact
@@ -85,11 +84,11 @@ jobs:
8584
- name: Checkout
8685
# see https://github.com/actions/checkout
8786
uses: actions/[email protected]
88-
- name: Setup Node.js ${{ matrix.node-version }}
89-
## see https://github.com/actions/setup-node
87+
- name: Setup Node.js ${{ env.NODE_ACTIVE_LTS }}
88+
# see https://github.com/actions/setup-node
9089
uses: actions/[email protected]
9190
with:
92-
node-version: '16' ## active LTS
91+
node-version: ${{ env.NODE_ACTIVE_LTS }}
9392
cache: "npm"
9493
cache-dependency-path: "**/package-lock.json"
9594
- name: install project

.github/workflows/release.yml

Lines changed: 150 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,60 +14,169 @@
1414
# dependency updates.
1515
#
1616
# You will also need to specify a value for the related commit message.
17+
1718
name: Release
1819

1920
on:
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+
2936
jobs:
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-
- uses: actions/[email protected]
37-
38-
- name: Setup Node.js
39-
uses: actions/[email protected]
40-
with:
41-
node-version: 12.x
45+
- name: Checkout code
46+
# see https://github.com/actions/checkout
47+
uses: actions/[email protected]
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+
uses: actions/[email protected]
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+
uses: actions/[email protected]
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+
uses: actions/[email protected]
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

Comments
 (0)