Skip to content

Commit 1837877

Browse files
authored
CI/CD (#5)
1 parent eb350bd commit 1837877

File tree

6 files changed

+286
-0
lines changed

6 files changed

+286
-0
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
### Motivation
2+
<!-- Why this pull request? -->
3+
4+
### Change description
5+
<!-- What does your code do? -->
6+
7+
### Additional Notes
8+
<!-- Link any useful metadata: Jira task, GitHub issue, ... -->
9+
10+
### Reviewer checklist
11+
12+
* [ ] PR address a single concern.
13+
* [ ] PR title and description are properly filled.
14+
* [ ] Changes will be merged in `main`.
15+
* [ ] Changes are covered by tests.
16+
* [ ] Logging is meaningful in case of troubleshooting.
17+
* [ ] History is clean, commit messages are meaningful and are well formatted.

.github/workflows/release-go-task.yml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/release-go-task.md
2+
name: Release
3+
4+
env:
5+
# As defined by the Taskfile's PROJECT_NAME variable
6+
PROJECT_NAME: aws-s3-integration
7+
# As defined by the Taskfile's DIST_DIR variable
8+
DIST_DIR: dist
9+
ARTIFACT_NAME: dist
10+
11+
on:
12+
push:
13+
tags:
14+
- "[0-9]+.[0-9]+.[0-9]+*"
15+
16+
jobs:
17+
create-release-artifacts:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v3
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Create changelog
27+
uses: arduino/create-changelog@v1
28+
with:
29+
tag-regex: '^[0-9]+\.[0-9]+\.[0-9]+.*$'
30+
filter-regex: '^\[(skip|changelog)[ ,-](skip|changelog)\].*'
31+
case-insensitive-regex: true
32+
changelog-file-path: "${{ env.DIST_DIR }}/CHANGELOG.md"
33+
34+
- name: Install Task
35+
uses: arduino/setup-task@v1
36+
with:
37+
repo-token: ${{ secrets.GITHUB_TOKEN }}
38+
version: 3.x
39+
40+
- name: Build
41+
run: task dist:all
42+
43+
- name: Upload artifacts
44+
uses: actions/upload-artifact@v2
45+
with:
46+
if-no-files-found: error
47+
name: ${{ env.ARTIFACT_NAME }}
48+
path: ${{ env.DIST_DIR }}
49+
50+
create-release:
51+
runs-on: ubuntu-latest
52+
53+
steps:
54+
- name: Download artifact
55+
uses: actions/download-artifact@v2
56+
with:
57+
name: ${{ env.ARTIFACT_NAME }}
58+
path: ${{ env.DIST_DIR }}
59+
60+
- name: Identify Prerelease
61+
# This is a workaround while waiting for create-release action
62+
# to implement auto pre-release based on tag
63+
id: prerelease
64+
run: |
65+
wget -q -P /tmp https://github.com/fsaintjacques/semver-tool/archive/3.0.0.zip
66+
unzip -p /tmp/3.0.0.zip semver-tool-3.0.0/src/semver >/tmp/semver && chmod +x /tmp/semver
67+
if [[ "$(/tmp/semver get prerel "${GITHUB_REF/refs\/tags\//}")" ]]; then echo "IS_PRE=true" >> $GITHUB_OUTPUT; fi
68+
69+
- name: Create Github Release and upload artifacts
70+
uses: ncipollo/release-action@v1
71+
with:
72+
token: ${{ secrets.GITHUB_TOKEN }}
73+
bodyFile: ${{ env.DIST_DIR }}/CHANGELOG.md
74+
draft: false
75+
prerelease: ${{ steps.prerelease.outputs.IS_PRE }}
76+
# NOTE: "Artifact is a directory" warnings are expected and don't indicate a problem
77+
# (all the files we need are in the DIST_DIR root)
78+
artifacts: ${{ env.DIST_DIR }}/*

.github/workflows/test-go-task.yml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/test-go-task.md
2+
name: Test Go
3+
4+
env:
5+
GO_VERSION: "1.22"
6+
7+
on:
8+
create:
9+
push:
10+
paths:
11+
- ".github/workflows/test-go-task.ya?ml"
12+
- "**/go.mod"
13+
- "**/go.sum"
14+
- "Taskfile.ya?ml"
15+
- "**.go"
16+
pull_request:
17+
paths:
18+
- ".github/workflows/test-go-task.ya?ml"
19+
- "**/go.mod"
20+
- "**/go.sum"
21+
- "Taskfile.ya?ml"
22+
- "**.go"
23+
workflow_dispatch:
24+
repository_dispatch:
25+
26+
jobs:
27+
run-determination:
28+
runs-on: ubuntu-latest
29+
outputs:
30+
result: ${{ steps.determination.outputs.result }}
31+
steps:
32+
- name: Determine if the rest of the workflow should run
33+
id: determination
34+
run: |
35+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
36+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
37+
if [[ \
38+
"${{ github.event_name }}" != "create" || \
39+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX \
40+
]]; then
41+
# Run the other jobs.
42+
RESULT="true"
43+
else
44+
# There is no need to run the other jobs.
45+
RESULT="false"
46+
fi
47+
48+
echo "result=$RESULT" >> $GITHUB_OUTPUT
49+
50+
test:
51+
name: test (${{ matrix.module.path }} - ${{ matrix.operating-system }})
52+
needs: run-determination
53+
if: needs.run-determination.outputs.result == 'true'
54+
55+
strategy:
56+
fail-fast: false
57+
58+
matrix:
59+
operating-system:
60+
- ubuntu-latest
61+
module:
62+
- path: ./
63+
codecov-flags: unit
64+
65+
runs-on: ${{ matrix.operating-system }}
66+
67+
steps:
68+
- name: Checkout repository
69+
uses: actions/checkout@v3
70+
71+
- name: Install Go
72+
uses: actions/setup-go@v3
73+
with:
74+
go-version: ${{ env.GO_VERSION }}
75+
76+
- name: Install Task
77+
uses: arduino/setup-task@v1
78+
with:
79+
repo-token: ${{ secrets.GITHUB_TOKEN }}
80+
version: 3.x
81+
82+
- name: Run tests
83+
env:
84+
GO_MODULE_PATH: ${{ matrix.module.path }}
85+
run: task go:test

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ vendor/
2121
.tool-versions
2222

2323
cover.out
24+
25+
dist/
26+
27+
coverage_unit.txt

DistTasks.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/release-go-task/DistTasks.yml
2+
version: "3"
3+
4+
# This taskfile is ideally meant to be project agnostic and could be dropped in
5+
# on other Go projects with minimal or no changes.
6+
#
7+
# To use it simply add the following lines to your main taskfile:
8+
# includes:
9+
# dist: ./DistTasks.yml
10+
#
11+
# The following variables must be declared in the including taskfile for the
12+
# build process to work correctly:
13+
# * DIST_DIR: the folder that will contain the final binaries and packages
14+
# * PROJECT_NAME: the name of the project, used in package name
15+
# * VERSION: the version of the project, used in package name and checksum file
16+
# * LD_FLAGS: flags used at build time
17+
# * PROVISIONING_BINARIES_FOLDER: provisioning binaries folder. Remember to REMOVE binaries folder as soon as it is removed from the project
18+
#
19+
# The project MUST contain a LICENSE.txt file in the root folder or packaging will fail.
20+
21+
vars:
22+
CONTAINER: "docker.elastic.co/beats-dev/golang-crossbuild"
23+
GO_VERSION: "1.22.6"
24+
CHECKSUM_FILE: "{{.VERSION}}-checksums.txt"
25+
26+
tasks:
27+
all:
28+
desc: Build for distribution for all platforms
29+
cmds:
30+
- task: Linux_64bit
31+
32+
Linux_64bit:
33+
desc: Builds Linux 64 bit binaries
34+
dir: "{{.DIST_DIR}}"
35+
cmds:
36+
- |
37+
docker run -v `pwd`/..:/home/build -w /home/build \
38+
-e CGO_ENABLED=0 \
39+
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
40+
--build-cmd "{{.BUILD_COMMAND}}" \
41+
-p "{{.BUILD_PLATFORM}}"
42+
43+
cp {{.PLATFORM_DIR}}/bootstrap bootstrap
44+
cp ../LICENSE LICENSE
45+
zip {{.PACKAGE_NAME}} bootstrap LICENSE
46+
rm bootstrap LICENSE
47+
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
48+
49+
vars:
50+
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_amd64"
51+
BUILD_COMMAND: "GOOS=linux CGO_ENABLED=0 go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/bootstrap -tags lambda.norpc lambda.go"
52+
BUILD_PLATFORM: "linux/amd64"
53+
CONTAINER_TAG: "{{.GO_VERSION}}-main"
54+
PACKAGE_PLATFORM: "Linux_64bit"
55+
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.zip"

Taskfile.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# See: https://taskfile.dev/#/usage
2+
version: "3"
3+
4+
includes:
5+
dist: ./DistTasks.yml
6+
7+
vars:
8+
# Path of the project's primary Go module:
9+
DEFAULT_GO_MODULE_PATH: ./
10+
DEFAULT_GO_PACKAGES:
11+
sh: |
12+
echo $(cd {{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}} && go list ./... | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"')
13+
PROJECT_NAME: "aws-s3-integration"
14+
DIST_DIR: "dist"
15+
# build vars
16+
COMMIT:
17+
sh: echo "$(git log --no-show-signature -n 1 --format=%h)"
18+
TIMESTAMP:
19+
sh: echo "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
20+
TIMESTAMP_SHORT:
21+
sh: echo "{{now | date "20060102"}}"
22+
TAG:
23+
sh: echo "$(git tag --points-at=HEAD 2> /dev/null | head -n1)"
24+
VERSION: "{{if .NIGHTLY}}nightly-{{.TIMESTAMP_SHORT}}{{else if .TAG}}{{.TAG}}{{else}}{{.PACKAGE_NAME_PREFIX}}git-snapshot{{end}}"
25+
CONFIGURATION_PACKAGE: github.com/arduino/aws-s3-integration/version
26+
27+
tasks:
28+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/go-task/Taskfile.yml
29+
go:build:
30+
desc: Build the Go code
31+
dir: "{{.DEFAULT_GO_MODULE_PATH}}"
32+
cmds:
33+
- GOOS=linux CGO_ENABLED=0 go build -o bootstrap -tags lambda.norpc lambda.go
34+
35+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-task/Taskfile.yml
36+
go:test:
37+
desc: Run unit tests
38+
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
39+
cmds:
40+
- |
41+
go test \
42+
-v \
43+
-short \
44+
-run '{{default ".*" .GO_TEST_REGEX}}' \
45+
{{default "-timeout 10m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} \
46+
-coverprofile=coverage_unit.txt \
47+
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}

0 commit comments

Comments
 (0)