Skip to content

Commit c8f06c4

Browse files
author
Juan Jose Medina
authored
Merge pull request #10 from bitnami/github-actions
Migrate to github actions
2 parents e863be3 + b5d69e3 commit c8f06c4

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

.github/workflows/main.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: CI
2+
3+
# Controls when the action will run.
4+
on:
5+
# Triggers the workflow on push or pull request events but only for the master branch
6+
push:
7+
branches:
8+
- master
9+
10+
release:
11+
types: [published]
12+
13+
pull_request:
14+
15+
# Allows you to run this workflow manually from the Actions tab
16+
workflow_dispatch:
17+
18+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
19+
jobs:
20+
# This workflow contains a single job called "build"
21+
build-and-test:
22+
runs-on: ubuntu-20.04
23+
name: Build and Test
24+
# Steps represent a sequence of tasks that will be executed as part of the job
25+
steps:
26+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
27+
- uses: actions/checkout@v2
28+
- uses: actions/setup-go@v2
29+
with:
30+
go-version: '^1.16.6' # The Go version to download (if necessary) and use.
31+
- name: Install Build Dependencies
32+
run: make get-build-deps
33+
- name: Download required modules
34+
run: make download
35+
- name: Vet
36+
run: make vet
37+
- name: Lint
38+
run: make lint
39+
- name: Cover
40+
run: make cover
41+
- name: Build
42+
run: |
43+
set -ex
44+
for dist in amd64 arm64; do
45+
target=out/ini-file-linux-$dist
46+
rm -rf "$target"
47+
make build/$dist TOOL_PATH="$target"
48+
file $target
49+
tar -C "$(dirname "$target")" -czf "$target.tar.gz" "$(basename "$target")"
50+
done
51+
- uses: actions/upload-artifact@v2
52+
with:
53+
name: built-binaries
54+
path: |
55+
out/*.tar.gz
56+
release:
57+
needs: [ 'build-and-test' ]
58+
if: startsWith(github.ref, 'refs/tags/')
59+
runs-on: ubuntu-20.04
60+
steps:
61+
- uses: actions/checkout@v2
62+
- uses: actions/download-artifact@v2
63+
with:
64+
path: ./artifacts
65+
- name: Set tag name
66+
id: vars
67+
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
68+
- name: Release
69+
run: |
70+
set -e
71+
create_digest_file() {
72+
local digest_file=${1:?You must provide the digest file path}
73+
shift
74+
for file in "$@"; do
75+
(
76+
cd "$(dirname "$file")"
77+
sha256sum "$(basename "$file")"
78+
) >> "$digest_file"
79+
done
80+
}
81+
assets=( ./artifacts/built-binaries/*.gz )
82+
83+
tag_name="${{ steps.vars.outputs.tag }}"
84+
checksums_file="${tag_name}_checksums.txt"
85+
create_digest_file "$checksums_file" "${assets[@]}"
86+
assets+=( "$checksums_file" )
87+
if gh release view "$tag_name" >/dev/null 2>/dev/null; then
88+
echo "Release $tag_name already exists. Updating"
89+
gh release upload "$tag_name" "${assets[@]}"
90+
else
91+
echo "Creating new release $tag_name"
92+
# Format checksums for the release text
93+
printf '```\n%s\n```' "$(<"$checksums_file")" > release.txt
94+
gh release create -t "$tag_name" "$tag_name" -F release.txt "${assets[@]}"
95+
fi
96+
env:
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)