This repository has been archived by the owner on Feb 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (70 loc) · 3.68 KB
/
build_and_push_go_lib.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
name: CI/CT workflow for packaged Go libraries
on:
workflow_dispatch:
jobs:
ci-ct-job-for-go-libraries:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go 1.21.3 🐹
uses: actions/setup-go@v4
with:
go-version: '1.21.3'
- name: Go mod tidy 🐹
run: |
target_folders=$(find . -type f -name '*.mod' -exec dirname {} \;)
for dir_name in $target_folders; do
absolute_path=$(realpath "$dir_name")
(cd "$absolute_path" && go mod tidy)
done
working-directory: ./libraries/go/common-lib/test
- name: Go test 🐹
run: |
target_folders=$(find . -type f -name '*.mod' -exec dirname {} \;)
for dir_name in $target_folders; do
absolute_path=$(realpath "$dir_name")
(cd "$absolute_path" && go test)
done
working-directory: ./libraries/go/common-lib/test
- name: Run Snyk to check for vulnerabilities in the source code 🔍/🛡️
uses: snyk/actions/golang@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: $(find ./libraries/go/common-lib/src -type f -name '*.mod' -exec dirname {} \;) --orgs=${{ secrets.SNYK_ORGANIZATION_ID }} --severity-threshold=high
- name: Create go package 📦
run: |
sudo apt-get install -y zip
#export BUILD_VERSION="0.1.0-dev${{ github.run_number }}"
export BUILD_VERSION="0.1.0"
target_folders=$(find . -type f -name '*.mod' -exec dirname {} \;)
for dir_name in $target_folders; do
absolute_path=$(realpath "$dir_name")
modified_dir_name=${dir_name//\//-}
modified_dir_name=${modified_dir_name:2}
echo $modified_dir_name
(cd "$absolute_path" && rm -rf .git/ go.sum && go mod tidy && find -type f | while read f; do zip common-lib-${modified_dir_name}-v${BUILD_VERSION}.zip "$f"; done)
done
working-directory: ./libraries/go/common-lib/src/
- name: Install CloudSmith dependencies
run: |
sudo apt-get install -y python3 python3-pip
sudo pip3 install --upgrade cloudsmith-cli
# When working with public go modules, consider utilizing git tags as proposed here: https://go.dev/doc/modules/publishing, https://go.dev/doc/modules/version-numbers
# Difficult setup with CloudSmith in current folder structure for the go sample library. See: https://help.cloudsmith.io/docs/go-registry
# - name: Push go modules package 📦 to CloudSmith. The uniqueness of the package version is essential.
# # To achieve this, the Git run number will serve as the revision number.
# # (Specifically development and quality assurance (QA) packages shall utilize revision numbers. Release packages not)
# run: |
# #export BUILD_VERSION="0.1.0-dev${{ github.run_number }}"
# export BUILD_VERSION="0.1.0"
# target_folders=$(find . -type f -name '*.mod' -exec dirname {} \;)
# for dir_name in $target_folders; do
# absolute_path=$(realpath "$dir_name")
# modified_dir_name=${dir_name//\//-}
# modified_dir_name=${modified_dir_name:2}
# echo $modified_dir_name
# (cd "$absolute_path" && cloudsmith push go ${{ secrets.CLOUDSMITH_REPOSITORY }} -k ${{ secrets.CLOUDSMITH_API_KEY }} common-lib-${modified_dir_name}-v${BUILD_VERSION}.zip)
# done
# working-directory: ./libraries/go/common-lib/src/