1+ name : CI
2+ on :
3+ push :
4+ branches :
5+ - develop
6+ - release*
7+ tags : [v*]
8+ paths-ignore :
9+ - README.md
10+ - CHANGELOG.md
11+ - LICENSE
12+ pull_request :
13+ # Sequence of patterns matched against refs/heads
14+ branches :
15+ - develop
16+ - release*
17+ paths-ignore :
18+ - README.md
19+ - CHANGELOG.md
20+ - LICENSE
21+
22+ env :
23+ project : ' focal-freedom-236620'
24+ image : ' controller'
25+
26+
27+ jobs :
28+ Build :
29+ runs-on : ubuntu-latest
30+ permissions :
31+ contents : ' read'
32+ id-token : ' write'
33+ packages : ' write'
34+ name : Preflight
35+ steps :
36+ - uses : actions/checkout@v3
37+ - uses : actions/setup-node@v3
38+ with :
39+ node-version : 18
40+ - run : npm ci
41+ - run : npm run standard
42+ - run : |
43+ npm i -g better-npm-audit
44+ npx better-npm-audit audit -p
45+
46+ Tests :
47+ needs : Build
48+ runs-on : ubuntu-latest
49+ permissions :
50+ contents : ' read'
51+ id-token : ' write'
52+ packages : ' write'
53+ issues : read
54+ checks : write
55+ pull-requests : write
56+ strategy :
57+ matrix :
58+ node : [ 16, 17, 16, 19 ]
59+ name : Node ${{ matrix.node }} Test
60+ steps :
61+ - uses : actions/checkout@v3
62+ - name : Setup Node ${{ matrix.node }} Test
63+ uses : actions/setup-node@v3
64+ with :
65+ node-version : ${{ matrix.node }}
66+ - name : Cache Node Modules
67+ uses : actions/cache@v3
68+ with :
69+ path : |
70+ node_modules
71+ key : ${{ runner.os }}-controller-node_modules-${{ hashFiles('package-lock.json') }}
72+ restore-keys : |
73+ ${{ runner.os }}-controller-node_modules-
74+ - run : npm ci
75+ - run : npm run test -- junit
76+ - run : npm run postman_test
77+ - name : Publish Test Results
78+ uses : EnricoMi/publish-unit-test-result-action@v2
79+ if : always()
80+ with :
81+ files : |
82+ *-results.xml
83+
84+ Publish :
85+ needs : [Build, Tests]
86+ runs-on : ubuntu-latest
87+ permissions :
88+ contents : ' read'
89+ id-token : ' write'
90+ packages : ' write'
91+ name : Publish Controller
92+ steps :
93+ - uses : actions/checkout@v3
94+ - uses : actions/setup-node@v3
95+ with :
96+ node-version : 18
97+ - run : npm ci
98+
99+ - name : npm version
100+ id : package-version
101+ uses : martinbeentjes/npm-get-version-action@v1.3.1
102+
103+ - name : package version
104+ shell : bash
105+ id : version
106+ run : |
107+ if [[ ${{ github.ref_name }} =~ ^v.* ]] ; then
108+ echo "pkg_version=${{ steps.package-version.outputs.current-version}}" >> "${GITHUB_OUTPUT}"
109+ else
110+ echo "pkg_version=${{ steps.package-version.outputs.current-version}}-${{ github.run_number }}" >> "${GITHUB_OUTPUT}"
111+ fi
112+
113+ - name : npm pack with version from package version
114+ run : |
115+ npm --no-git-tag-version version ${{ steps.version.outputs.pkg_version }}
116+ npm pack
117+
118+ - name : Login to Github Container Registry
119+ uses : docker/login-action@v2
120+ with :
121+ registry : " ghcr.io"
122+ username : ${{ github.actor }}
123+ password : ${{ github.token }}
124+
125+ - name : Build and Push to ghcr
126+ uses : docker/build-push-action@v3
127+ id : build_push_ghcr
128+ with :
129+ file : Dockerfile.dev
130+ push : true
131+ tags : |
132+ ghcr.io/eclipse-iofog/controller:${{ steps.version.outputs.pkg_version }}
133+ ghcr.io/eclipse-iofog/controller:latest
134+ build-args : PKG_VERSION=${{ steps.version.outputs.pkg_version }}
135+
136+ - name : Build and Push to GCR
137+ id : build_push_gcr
138+ uses : RafikFarhad/push-to-gcr-github-action@v5-beta
139+ with :
140+ gcloud_service_key : ${{ secrets.GCLOUD_SERVICE_KEY }}
141+ registry : gcr.io
142+ project_id : ${{ env.project }}
143+ image_name : ${{ env.image }}
144+ image_tag : latest,${{ steps.version.outputs.pkg_version }}
145+ dockerfile : Dockerfile.dev
146+ build_args : PKG_VERSION=${{ steps.version.outputs.pkg_version }}
147+
148+ - run : ls
149+
150+ - name : Publish package to packagecloud
151+ if : ${{ steps.build_push_gcr.outcome }} == 'success'
152+ uses : danielmundi/upload-packagecloud@v1
153+ with :
154+ PACKAGE-NAME : iofog-iofogcontroller-${{ steps.version.outputs.pkg_version }}.tgz
155+ PACKAGECLOUD-USERNAME : iofog
156+ PACKAGECLOUD-REPO : iofog-controller-snapshots
157+ PACKAGECLOUD-DISTRIB : node
158+ PACKAGECLOUD-TOKEN : ${{ secrets.packagecloud_token }}
0 commit comments