forked from jriguera/otel-helloworldprocessor
-
Notifications
You must be signed in to change notification settings - Fork 4
167 lines (147 loc) · 5.56 KB
/
release-artifacts.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
name: Release Docker image
on:
workflow_dispatch: { }
push:
branches:
- "main"
tags:
- '**'
env:
# Default image for the Chart
DOCKER_IMAGE_NAME: otel-collector
DOCKER_REGISTRY: ghcr.io/${{ github.repository }}
DOCKER_BUILD_DIR: '.'
permissions: {}
jobs:
compile:
runs-on: ubuntu-latest
outputs:
artifact: ${{ steps.artifact.outputs.artifact-id }}
version: ${{ steps.versions.outputs.version }}
buildname: ${{ steps.versions.outputs.build-name }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup golang stable
uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Get build versions
id: versions
run: |
awk -F':' '/^[[:blank:]]+otelcol_version[[:blank:]]*:/{ gsub("\"","",$2); gsub(" ", "", $2); print "otelcol-version="$2 }' builder-config.yaml >> $GITHUB_OUTPUT
awk -F':' '/^[[:blank:]]+output_path[[:blank:]]*:/{ gsub("\"","",$2); gsub(" ", "", $2); print "build-path="$2 }' builder-config.yaml >> $GITHUB_OUTPUT
awk -F':' '/^[[:blank:]]+name[[:blank:]]*:/{ gsub("\"","",$2); gsub(" ", "", $2); print "build-name="$2 }' builder-config.yaml >> $GITHUB_OUTPUT
awk -F':' '/^[[:blank:]]+version[[:blank:]]*:/{ gsub("\"","",$2); gsub(" ", "", $2); print "version="$2 }' builder-config.yaml >> $GITHUB_OUTPUT
- name: Download the collector builder
run: |
curl -Ss -fL -o ocb https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/cmd%2Fbuilder%2Fv${VERSION}/ocb_${VERSION}_linux_amd64
chmod +x ocb
env:
VERSION: "${{ steps.versions.outputs.otelcol-version }}"
- name: Build the OTEL collectory binary
run: |
./ocb --config builder-config.yaml
- name: Archive binary
id: artifact
uses: actions/upload-artifact@v4
with:
name: "otelcol-${{ steps.versions.outputs.version }}_linux_amd64"
retention-days: 1
path: "${{ steps.versions.outputs.build-path }}/${{ steps.versions.outputs.build-name }}"
if-no-files-found: error
overwrite: true
build-image:
permissions:
contents: read
packages: write
needs:
- compile
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifact
id: artifact
uses: actions/download-artifact@v4
with:
name: "otelcol-${{ needs.compile.outputs.version }}_linux_amd64"
path: otelcol-dev
- name: Get metadata for Docker image
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}/${{ env.DOCKER_IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=tag
type=ref,event=branch
type=sha
- name: Build and export to Docker
uses: docker/build-push-action@v6
with:
context: ${{ env.DOCKER_BUILD_DIR }}
build-args: |
"OTEL_BIN=${{ steps.artifact.outputs.download-path }}/${{ needs.compile.outputs.build-name }}"
load: true
tags: otelcol
# - name: Test
# run: |
# docker run --rm otelcol
- name: Log in to the GitHub Container registry
if: ${{ (github.event_name != 'pull_request') && (startsWith(github.ref, 'refs/tags/')) }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push to Github Packages
uses: docker/build-push-action@v6
if: ${{ (github.event_name != 'pull_request') && (startsWith(github.ref, 'refs/tags/')) }}
with:
context: ${{ env.DOCKER_BUILD_DIR }}
push: ${{ github.event_name != 'pull_request' }}
build-args: |
"OTEL_BIN=${{ steps.artifact.outputs.download-path }}/${{ needs.compile.outputs.build-name }}"
tags: |
${{ steps.meta.outputs.tags }}
${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.compile.outputs.version }}
labels: ${{ steps.meta.outputs.labels }}
release:
permissions:
contents: write
packages: read
needs:
- compile
- build-image
if: ${{ (github.event_name != 'pull_request') && (startsWith(github.ref, 'refs/tags/')) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get artifact
id: artifact
uses: actions/download-artifact@v4
with:
name: "otelcol-${{ needs.compile.outputs.version }}_linux_amd64"
path: otelcol-dev
- name: Get list of artifacts
run: |
cd "${{ steps.artifact.outputs.download-path }}"
mkdir "otelcol-custom_${{ needs.compile.outputs.version }}"
cp "${{ needs.compile.outputs.build-name }}" "otelcol-custom_${{ needs.compile.outputs.version }}/otelcol-custom_${{ needs.compile.outputs.version }}_linux_amd64"
mv "${{ needs.compile.outputs.build-name }}" "otelcol-custom_${{ needs.compile.outputs.version }}_linux_amd64.bin"
tar zcvf "otelcol-custom_${{ needs.compile.outputs.version }}.tgz" "otelcol-custom_${{ needs.compile.outputs.version }}"
rm "otelcol-custom_${{ needs.compile.outputs.version }}"
- name: Create a Release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: "${{ steps.artifact.outputs.download-path }}/*"