-
Notifications
You must be signed in to change notification settings - Fork 0
1086 lines (958 loc) · 37.3 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SPDX-FileCopyrightText: 2022-2024 Comcast Cable Communications Management, LLC
# SPDX-FileCopyrightText: 2022 Weston Schmidt <[email protected]>
# SPDX-License-Identifier: Apache-2.0
# Copied from github.com/goschtalt/.github
# @example=## Golang CI Workflow Sample
## SPDX-FileCopyrightText: 2023 Comcast Cable Communications Management, LLC
## SPDX-License-Identifier: Apache-2.0
#---
#name: 'CI'
#
#on:
# push:
# branches:
# - main
# paths-ignore:
# - README.md
# tags:
# - 'v[0-9]+.[0-9]+.[0-9]+'
# pull_request:
# workflow_dispatch:
#
#jobs:
# ci:
# uses: xmidt-org/shared-go/.github/workflows/ci.yml@6a0bec30f42c318c0c1d06705f3f60911ed7c610 # v3.2.0
# with:
# release-type: program # or: library
# secrets: inherit
---
name: 'CI Workflow'
on:
workflow_call:
inputs:
# General or common inputs. These cross cut concerns generally and shouldn't
# be included in the more targetted sections below.
go-version:
description: "The go version to use. Example: '1.20.x'"
required: false
type: string
default: '^1.20.x'
go-version-latest:
description: "Will always use the latest version of go available."
required: false
type: boolean
default: true
go-generate-skip:
description: "Skip running go generate if needed."
required: false
type: boolean
default: true
go-generate-deps:
description: |
The line sparated list of go generate dependencies to install via
`go install` prior to running `go generate`.
required: false
type: string
default: ''
working-directory:
description: 'The working directory for this project.'
required: false
type: string
default: .
description:
description: 'What this project/package does.'
required: false
type: string
default: '${{ github.repository }} does something important.'
license:
description: "The license this project should use if it doesn't support REUSE/SPDX."
required: false
type: string
# Alphabetize the sections & prefix the names of the sections to the
# parameters associated, so maintenance and discovery is easier.
# Build focused
build-skip:
description: 'Skip building the program.'
required: false
type: boolean
default: false
# Goreportcard focused
goreportcard-skip:
description: 'Skip running the goreportcard update.'
required: false
type: boolean
default: false
# Lint focused
lint-skip:
description: 'Skip running the lint check.'
required: false
type: boolean
default: false
lint-timeout:
description: 'The timeout to pass on to the linter.'
required: false
type: string
default: '5m'
lint-version:
description: 'The working directory for this project.'
required: false
type: string
default: 'latest'
# License focused
license-skip:
description: 'Skip building the license check.'
required: false
type: boolean
default: false
# Release focused
release-arch-amd64:
description: "Set to enable amd64 binary and dockers to be built."
required: false
type: boolean
default: true
release-arch-arm64:
description: "Set to enable arm64 binary and dockers to be built."
required: false
type: boolean
default: true
release-binary-name:
description: "If the project needs a custom name, use set it here."
required: false
type: string
default: ""
release-custom-file:
description: "If the project needs a custom release file, use that instead."
required: false
type: boolean
default: false
release-docker:
description: "If set to true, release a container to gocr as well."
required: false
type: boolean
default: false
release-docker-extras:
description: |
Provides a way to set the `extra_files` field with the list of
files/dirs to make available.
required: false
type: string
release-docker-file:
description: |
Set to the docker file and path if you don't want the default of
`Dockerfile` in the project root.
required: false
type: string
default: 'Dockerfile'
release-docker-latest:
description: "If set to true, release this container as the latest."
required: false
type: boolean
default: false
release-docker-major:
description: |
If set to true, release this container as the latest for
the major version.
required: false
type: boolean
default: false
release-docker-minor:
description: "If set to true, release this container as the latest for the minor version."
required: false
type: boolean
default: false
release-main-package:
description: "Path to main.go file or main package."
required: false
type: string
default: '.'
release-project-name:
description: "The project name / binary name to use if not the repo name."
required: false
type: string
default: ''
release-rpms:
description: "If set to true, release generic rpms as well."
required: false
type: boolean
default: true
release-skip:
description: 'Skip releasing the program.'
required: false
type: boolean
default: false
release-skip-publish:
description: "Set to --skip-publish to skip publishing."
required: false
type: string
default: ''
release-type:
description: "The type of artifact to expect and release. [ `library`, `program` ]."
required: true
type: string
release-with-extra-contents:
description: |
The list of any extra files to include in the packaged releases. See
goreleaser nfpm contents for examples.
required: false
type: string
default: ''
release-with-unique-user:
description: |
If set to true will add a user and group with the same name as the
program. Otherwise root is assumed.
required: false
type: string
default: "true"
# Copyright focused
copyright-skip:
description: 'Skip validating that all files have copyright and licensing information.'
required: false
type: boolean
default: false
# Style/code format focused
style-skip:
description: 'Skip building the gofmt check.'
required: false
type: boolean
default: false
# Unit test focused
tests-race:
description: |
If set to "true" (default), race condition checking will be performed
during unit tests. Otherwise no race condition checking will be done.
required: false
type: boolean
default: true
tests-skip:
description: 'Skip running the unit tests.'
required: false
type: boolean
default: false
# Artifact uploading focused
upload-skip:
description: 'Skip uploading the artifacts.'
required: false
type: boolean
default: false
# YML linting focused
yaml-lint-skip:
description: 'Skip linting yaml files.'
required: false
type: boolean
default: true
jobs:
build_program:
runs-on: [ ubuntu-latest ]
if: inputs.build-skip == false
name: Build Go Program
steps:
- name: Checkout the code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup go version
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version: ${{ inputs.go-version }}
check-latest: ${{ inputs.go-version-latest }}
cache-dependency-path: ${{ inputs.working-directory }}
- name: Fetch go:generate dependencies
if: inputs.go-generate-skip == false
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
deps=$(echo ${{ inputs.go-generate-deps }} | sed -e 's/[\r\n\t]/ /g' | tr "," "\n")
for dep in $deps
do
go install ${dep}
done
- name: Run go generate
if: inputs.go-generate-skip == false
working-directory: ${{ inputs.working-directory }}
run: |
go generate ./...
# Run build of the application
- name: Run build
working-directory: ${{ inputs.working-directory }}
run: |
go build ./...
unit_test:
runs-on: [ ubuntu-latest ]
name: Go Unit Tests
if: inputs.tests-skip == false
steps:
- name: Checkout the code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Setup go version
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version: ${{ inputs.go-version }}
check-latest: ${{ inputs.go-version-latest }}
cache-dependency-path: ${{ inputs.working-directory }}
- name: Fetch go:generate dependencies
if: inputs.go-generate-skip == false
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
deps=$(echo ${{ inputs.go-generate-deps }} | sed -e 's/[\r\n\t]/ /g' | tr "," "\n")
for dep in $deps
do
go install ${dep}
done
- name: Run go generate
if: inputs.go-generate-skip == false
working-directory: ${{ inputs.working-directory }}
run: |
go generate ./...
# Run testing on the code
- name: Run testing
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
go test -v ${{ inputs.tests-race && '-race' || '' }} -coverprofile=coverage.txt ./...
go test ${{ inputs.tests-race && '-race' || '' }} -json > report.json ./...
# upload report as artifact
- name: Archive unit tests report
if: inputs.upload-skip == false
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
name: report
path: ${{ inputs.working-directory }}/report.json
# upload coverage as artifact
- name: Archive code coverage results
if: inputs.upload-skip == false
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
name: coverage
path: ${{ inputs.working-directory }}/coverage.txt
- name: Send results to codecov.io
uses: codecov/codecov-action@1e68e06f1dbfde0e4cefc87efeba9e4643565303 # v5.1.2
with:
directory: ${{ inputs.working-directory }}
flags: unittests
token: ${{ secrets.CODECOV_TOKEN }}
docker_check:
if: inputs.release-docker
runs-on: [ ubuntu-latest ]
outputs:
docker_file_present: ${{ steps.build.outputs.docker_file_present }}
name: Check Docker Build
steps:
- name: Checkout the code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Build image
id: build
run: |
# Check for a dockerfile
if [ -f ${{ inputs.docker-directory }}/${{ inputs.docker-file}} ]; then
echo "docker_file_present=true" >> $GITHUB_ENV
d=`dirname ${{ inputs.release-docker-file }}`
f=`basename ${{ inputs.release-docker-file }}`
docker build ${d} -f ${f} \
--tag ghcr.io/${{ github.repository }}:latest \
--label "org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
--label "org.opencontainers.image.revision=${{ github.sha }}"
fi
goreportcard:
runs-on: [ ubuntu-latest ]
if: |
inputs.goreportcard-skip == false &&
github.event_name == 'push' ||
github.event_name == 'workflow_dispatch'
steps:
- name: Go report card
uses: creekorful/[email protected]
style:
runs-on: [ ubuntu-latest ]
name: Go format check
if: inputs.style-skip == false
steps:
- name: Checkout the code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup go version
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version: ${{ inputs.go-version }}
check-latest: ${{ inputs.go-version-latest }}
cache-dependency-path: ${{ inputs.working-directory }}
- name: Run gofmt
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
gofmt -d $(find . -path ./vendor -prune -o -name '*.go' -print) > fmt.patch
# Error check & fail if any format mismatches are detected.
if [ $(wc fmt.patch | awk '{print $1}') -ne 0 ]; then
cat fmt.patch;
exit 1;
fi
- name: Archive code style results
if: inputs.upload-skip == false
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
name: fmt
path: ${{ inputs.working-directory }}/fmt.patch
retention-days: 10
golint:
runs-on: [ ubuntu-latest ]
name: Go Lint
if: inputs.lint-skip == false
steps:
- name: Checkout the code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Go
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version: ${{ inputs.go-version }}
check-latest: ${{ inputs.go-version-latest }}
cache-dependency-path: ${{ inputs.working-directory }}
- name: Fetch go:generate dependencies
if: inputs.go-generate-skip == false
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
deps=$(echo ${{ inputs.go-generate-deps }} | sed -e 's/[\r\n\t]/ /g' | tr "," "\n")
for dep in $deps
do
go install ${dep}
done
- name: Run go generate
if: inputs.go-generate-skip == false
working-directory: ${{ inputs.working-directory }}
run: |
go generate ./...
# working-directory and only-new-issues aren't compatible so run for entire repo each time.
- name: Lint Entire Repo
if: github.event_name != 'pull_request'
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1
with:
version: ${{ inputs.lint-version }}
working-directory: ${{ inputs.working-directory }}
args: --timeout ${{ inputs.lint-timeout }}
skip-cache: true
ymllint:
runs-on: [ ubuntu-latest ]
if: inputs.yaml-lint-skip == false
steps:
- name: Checkout the code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: ibiqlik/action-yamllint@2576378a8e339169678f9939646ee3ee325e845c # v3.1.1
copyright:
runs-on: [ ubuntu-latest ]
if: inputs.copyright-skip == false
steps:
- name: Checkout the code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: REUSE Compliance Check
uses: fsfe/reuse-action@bb774aa972c2a89ff34781233d275075cbddf542 # v5
license:
name: License Checker
runs-on: [ ubuntu-latest ]
if: inputs.license-skip == false
steps:
- name: Checkout the code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Go
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version: ${{ inputs.go-version }}
check-latest: ${{ inputs.go-version-latest }}
cache-dependency-path: ${{ inputs.working-directory }}
# setup ruby environment before running github/setup-licensed
- name: Setup Ruby
uses: ruby/setup-ruby@4a9ddd6f338a97768b8006bf671dfbad383215f4 # v1.207.0
with:
ruby-version: ruby
- name: Setup licensed
uses: github/setup-licensed@be11bcbb82e3140b6cf260e647c3efeeca8fcefd #v1.3.1
with:
version: 4.x
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Fetch Org Approved Licenses & merge to local
shell: bash
run: |
if [ -f .licensed.yml ]; then
echo "Please submit these licenses to the shared list..."
mv .licensed.yml .licensed_local.yml
fi
if [ -f .licensed.json ]; then
echo "JSON is not supported. Please use .licensed.yml or submit a patch."
fi
if [ ! -f .licensed_local.yml ]; then
touch .licensed_local.yml
fi
curl -L -s -f \
--max-time 10 \
--retry 5 \
--retry-delay 1 \
-H 'Accept: application/vnd.github.v3.raw' \
https://api.github.com/repos/xmidt-org/.github/contents/licensing/org-approved.yml?ref=main \
-o .licensed_common.yml
yq eval-all '. as $item ireduce ({}; . *+ $item)' .licensed_local.yml .licensed_common.yml > .licensed.yml
- name: Fetch all dependencies
working-directory: ${{ inputs.working-directory }}
run: |
go get ./...
- name: Examine the licenses
run: |
licensed cache
- name: Validate compliance
run: |
licensed status -f yaml > licensing.yml || true
yq eval 'del(.apps[].sources[].dependencies[] | select(.allowed == "true") )' licensing.yml > disallowed.yml
licensed status
- name: Archive license results
if: always() && inputs.upload-skip == false
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
name: licensing
path: |
${{ inputs.working-directory }}/licensing.yml
${{ inputs.working-directory }}/disallowed.yml
retention-days: 30
release:
permissions:
contents: write
packages: write
name: Release
needs: [ build_program, unit_test, style, golint, license, copyright, ymllint ]
if: |
always() &&
inputs.release-skip == false &&
startsWith(github.ref, 'refs/tags/') &&
needs.build_program.result != 'failure' &&
needs.unit_test.result != 'failure' &&
needs.style.result != 'failure' &&
needs.golint.result != 'failure' &&
needs.ymllint.result != 'failure' &&
needs.copyright.result != 'failure' &&
needs.license.result != 'failure'
runs-on: [ ubuntu-latest ]
steps:
- name: Install syft for sbom generation
uses: anchore/sbom-action/download-syft@df80a981bc6edbc4e220a492d3cbe9f5547a6e75 # v0.17.9
- name: Checkout the code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Fetch tags for TagBody, TagSubject and TagContents
run: git fetch --force --tags
- name: Setup go version
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version: ${{ inputs.go-version }}
check-latest: ${{ inputs.go-version-latest }}
cache-dependency-path: ${{ inputs.working-directory }}
- name: Fetch go:generate dependencies
if: inputs.go-generate-skip == false
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
deps=$(echo ${{ inputs.go-generate-deps }} | sed -e 's/[\r\n\t]/ /g' | tr "," "\n")
for dep in $deps
do
go install ${dep}
done
- name: Generate common rules to the .goreleaser.yml file
if: inputs.release-custom-file == false
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
project_name=${{ inputs.release-project-name }}
if [[ $project_name == "" ]]; then
project_name=$(echo ${{ github.repository }} | sed 's:.*/::')
fi
echo "PROJECT_NAME=${project_name}" >> $GITHUB_ENV
echo "---" > .goreleaser.yml
gecho() { echo "$1" >> .goreleaser.yml ; }
gecho "project_name: ${project_name}"
gecho ""
if [[ ${{ inputs.go-generate-skip }} == "false" ]]; then
gecho "before:"
gecho " hooks:"
gecho " - go generate ./..."
gecho ""
fi
gecho ""
gecho "changelog:"
gecho " use: github"
gecho " sort: asc"
gecho " filters:"
gecho " exclude:"
gecho " - '^test:'"
gecho " - '^chore'"
gecho " - 'merge conflict'"
gecho " - Merge pull request"
gecho " - Merge remote-tracking branch"
gecho " - Merge branch"
gecho " - go mod tidy"
gecho " groups:"
gecho " - title: 'Dependency Updates'"
gecho " regexp: '^.*?(feat|fix)\(deps\)!?:.+$'"
gecho " order: 300"
gecho " - title: 'New Features'"
gecho " regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'"
gecho " order: 100"
gecho " - title: 'Bug Fixes'"
gecho " regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'"
gecho " order: 200"
gecho " - title: 'Documentation Updates'"
gecho " regexp: ^.*?doc(\([[:word:]]+\))??!?:.+$"
gecho " order: 400"
gecho " - title: Other Work"
gecho " order: 9999"
gecho ""
- name: Generate sbom rules to the .goreleaser.yml file
if: |
inputs.release-custom-file == false &&
inputs.release-type == 'program'
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
gecho() { echo "$1" >> .goreleaser.yml ; }
gecho "sboms:"
gecho " - id: archive"
gecho " artifacts: archive"
if [[ "${{ inputs.release-rpms }}" == "true" ]]; then
gecho " - id: package"
gecho " artifacts: package"
fi
gecho ""
- name: Generate the library .goreleaser.yml file
if: |
inputs.release-custom-file == false &&
inputs.release-type == 'library'
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
gecho() { echo "$1" >> .goreleaser.yml ; }
gecho "builds:"
gecho " - skip: true"
gecho ""
- name: Generate the program .goreleaser.yml file
if: |
inputs.release-custom-file == false &&
inputs.release-type == 'program'
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
gecho() { echo "$1" >> .goreleaser.yml ; }
gecho "builds:"
gecho " -"
gecho " main: '${{ inputs.release-main-package }}'"
if [[ "${{ inputs.release-binary-name }}" != "" ]]; then
gecho " binary: '${{ inputs.release-binary-name }}'"
fi
gecho " env:"
gecho " - CGO_ENABLED=0"
gecho " goos:"
gecho " - linux"
gecho " goarch:"
if [[ "${{ inputs.release-arch-amd64 }}" == "true" ]]; then
gecho " - amd64"
fi
if [[ "${{ inputs.release-arch-arm64 }}" == "true" ]]; then
gecho " - arm64"
fi
gecho " mod_timestamp: \"{{ .CommitTimestamp }}\""
gecho ""
gecho "archives:"
gecho " - format: tar.gz"
gecho " wrap_in_directory: true"
gecho " format_overrides:"
gecho " - goos: windows"
gecho " format: zip"
gecho " name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'"
gecho ""
gecho "checksum:"
gecho " name_template: '{{.ProjectName}}-{{.Version}}-checksums.txt'"
gecho " algorithm: sha512"
gecho ""
gecho "release:"
gecho " extra_files:"
gecho " - glob: ./.extra_files/**"
gecho ""
gecho "dockers:"
- name: Generate the amd64 docker .goreleaser.yml section
if: |
inputs.release-custom-file == false &&
inputs.release-type == 'program' &&
inputs.release-docker == true &&
inputs.release-arch-amd64 == true
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
gecho() { echo "$1" >> .goreleaser.yml ; }
gecho " - use: buildx"
gecho " goos: linux"
gecho " goarch: amd64"
gecho " build_flag_templates:"
gecho " - \"--platform=linux/amd64\""
gecho " - \"--label=org.opencontainers.image.created={{.Date}}\""
gecho " - \"--label=org.opencontainers.image.url=https://github.com/${{ github.repository }}\""
gecho " - \"--label=org.opencontainers.image.title={{.ProjectName}}\""
gecho " - \"--label=org.opencontainers.image.revision={{.FullCommit}}\""
gecho " - \"--label=org.opencontainers.image.source=https://github.com/${{ github.repository }}\""
gecho " - \"--label=org.opencontainers.image.version={{.Version}}\""
gecho " image_templates:"
gecho " - ghcr.io/${{ github.repository }}:{{ .Tag }}-amd64"
if [[ "${{ inputs.release-docker-major }}" == "true" ]]; then
gecho " - ghcr.io/${{ github.repository }}:v{{ .Major }}-amd64"
fi
if [[ "${{ inputs.release-docker-minor }}" == "true" ]]; then
gecho " - ghcr.io/${{ github.repository }}:v{{ .Major }}.{{ .Minor }}-amd64"
fi
if [[ "${{ inputs.release-docker-latest }}" == "true" ]]; then
gecho " - ghcr.io/${{ github.repository }}:latest-amd64"
fi
if [[ "${{ inputs.release-skip-publish }}" == "--skip-publish" ]]; then
gecho " skip_push: true"
fi
gecho " dockerfile: '${{ inputs.release-docker-file }}'"
extras='${{ inputs.release-docker-extras }}'
if [[ ! -z "${extras}" ]]; then
gecho " extra_files:"
extras=$(echo "${extras}" | sed -e 's/[\r\n\t]/ /g' | tr "," "\n")
for extra in $extras
do
gecho " - ${extra}"
done
fi
gecho ""
- name: Generate the arm64 docker .goreleaser.yml section
if: |
inputs.release-custom-file == false &&
inputs.release-type == 'program' &&
inputs.release-docker == true &&
inputs.release-arch-arm64 == true
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
gecho() { echo "$1" >> .goreleaser.yml ; }
gecho " - use: buildx"
gecho " goos: linux"
gecho " goarch: arm64"
gecho " build_flag_templates:"
gecho " - \"--platform=linux/arm64\""
gecho " - \"--label=org.opencontainers.image.created={{.Date}}\""
gecho " - \"--label=org.opencontainers.image.url=https://github.com/${{ github.repository }}\""
gecho " - \"--label=org.opencontainers.image.source=https://github.com/${{ github.repository }}\""
gecho " - \"--label=org.opencontainers.image.title={{.ProjectName}}\""
gecho " - \"--label=org.opencontainers.image.revision={{.FullCommit}}\""
gecho " - \"--label=org.opencontainers.image.version={{.Version}}\""
gecho " image_templates:"
gecho " - ghcr.io/${{ github.repository }}:{{ .Tag }}-arm64"
if [[ "${{ inputs.release-docker-major }}" == "true" ]]; then
gecho " - ghcr.io/${{ github.repository }}:v{{ .Major }}-arm64"
fi
if [[ "${{ inputs.release-docker-minor }}" == "true" ]]; then
gecho " - ghcr.io/${{ github.repository }}:v{{ .Major }}.{{ .Minor }}-arm64"
fi
if [[ "${{ inputs.release-docker-latest }}" == "true" ]]; then
gecho " - ghcr.io/${{ github.repository }}:latest-arm64"
fi
if [[ "${{ inputs.release-skip-publish }}" == "--skip-publish" ]]; then
gecho " skip_push: true"
fi
gecho " dockerfile: '${{ inputs.release-docker-file }}'"
extras='${{ inputs.release-docker-extras }}'
if [[ ! -z "${extras}" ]]; then
gecho " extra_files:"
extras=$(echo "${extras}" | sed -e 's/[\r\n\t]/ /g' | tr "," "\n")
for extra in $extras
do
gecho " - ${extra}"
done
fi
gecho ""
- name: Determine project license(s)
if: |
inputs.release-custom-file == false &&
inputs.release-type == 'program' &&
inputs.release-rpms == true
shell: bash
run: |
echo "LICENSE=unknown" >> $GITHUB_ENV
if [ -d LICENSES ]; then
found=`ls LICENSES/|sed 's|\.txt\>||'`
echo "LICENSE='$found'" >> $GITHUB_ENV
fi
if [[ "${{ inputs.license }}" != "" ]]; then
echo "LICENSE='${{ inputs.license }}'" >> $GITHUB_ENV
fi
- name: Generate the rpm generation section
if: |
inputs.release-custom-file == false &&
inputs.release-type == 'program' &&
inputs.release-rpms == true
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
gecho() { echo "$1" >> .goreleaser.yml ; }
gecho "nfpms:"
gecho " -"
gecho " license: ${{ env.LICENSE }}"
gecho " maintainer: ${{ github.repository_owner }}"
gecho " homepage: ${{ github.repository }}"
gecho " rpm:"
gecho " group: System Environment/Daemons"
gecho " signature:"
gecho " key_file: .secrets/rpm_gpg_private_key_file"
gecho " description: |-"
gecho " ${{ inputs.description }}"
gecho " formats:"
gecho " - rpm"
gecho " file_name_template: >-"
gecho " {{ .PackageName }}-{{ .Version }}."
gecho " {{- if eq .Arch \"amd64\" }}x86_64"
gecho " {{- else if eq .Arch \"arm64\" }}aarch64{{ end }}"
gecho " contents:"
gecho " - dst: /var/log/${{ env.PROJECT_NAME }}/"
gecho " type: dir"
gecho " file_info:"
gecho " mode: 0755"
if [[ "${{ inputs.release-with-unique-user }}" == "true" ]]; then
gecho " owner: ${{ env.PROJECT_NAME }}"
gecho " group: ${{ env.PROJECT_NAME }}"
fi
gecho " - src: ${{ env.PROJECT_NAME }}.log"
gecho " dst: /var/log/${{ env.PROJECT_NAME }}/${{ env.PROJECT_NAME }}.log"
gecho " file_info:"
gecho " mode: 0644"
if [[ "${{ inputs.release-with-unique-user }}" == "true" ]]; then
gecho " owner: ${{ env.PROJECT_NAME }}"
gecho " group: ${{ env.PROJECT_NAME }}"
fi
gecho " - dst: /etc/${{ env.PROJECT_NAME }}/"
gecho " type: dir"
gecho " file_info:"
gecho " mode: 0755"
if [[ "${{ inputs.release-with-unique-user }}" == "true" ]]; then
gecho " owner: ${{ env.PROJECT_NAME }}"
gecho " group: ${{ env.PROJECT_NAME }}"
fi
if [[ "${{ inputs.release-with-extra-contents }}" != "" ]]; then
mapfile -t lines< <(echo "${LINES}")
for line in "${lines[@]}"
do
gecho " $line"
done
fi
if [[ "${{ inputs.release-with-unique-user }}" == "true" ]]; then
gecho " scripts:"
gecho " preinstall: .scripts/preinstall.sh"
gecho " overrides:"
gecho " rpm:"
gecho " dependencies:"
gecho " - shadow-utils"
fi
gecho ""
env:
LINES: ${{ inputs.release-with-extra-contents }}
- name: Generate the rpm scripts & support files
if: |
inputs.release-custom-file == false &&
inputs.release-type == 'program' &&
inputs.release-rpms == true
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
mkdir -p .scripts
touch ${{ env.PROJECT_NAME }}.log
mkdir -p .extra_files
mkdir -p .secrets
echo "${{ vars.RPM_GPG_PUBLIC_KEY }}" > .extra_files/RPM-GPG-KEY-comcast-xmidt
echo "${{ secrets.RPM_GPG_PRIVATE_KEY }}" > .secrets/rpm_gpg_private_key_file
if [[ "${{ inputs.release-with-unique-user }}" == "true" ]]; then
gecho() { echo "$1" >> .scripts/preinstall.sh ; }
rm -f .scripts/preinstall.sh
gecho 'getent group ${{ env.PROJECT_NAME }} > /dev/null || groupadd -r ${{ env.PROJECT_NAME }}'
gecho 'getent passwd ${{ env.PROJECT_NAME }} > /dev/null || \'
gecho ' useradd \'
gecho ' -d /var/run/${{ env.PROJECT_NAME }} \'
gecho ' -r \'
gecho ' -g ${{ env.PROJECT_NAME }} \'
gecho ' -s /sbin/nologin \'
gecho ' -c "${{ env.PROJECT_NAME }} server" \'
gecho ' ${{ env.PROJECT_NAME }}'
gecho ""
fi
- name: Show the .goreleaser.yml file
working-directory: ${{ inputs.working-directory }}