-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (117 loc) · 4.24 KB
/
publish.yml
File metadata and controls
131 lines (117 loc) · 4.24 KB
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
name: Publishing
on:
push:
branches:
- main
workflow_dispatch:
inputs:
source_branch:
description: 'Source branch'
required: true
default: 'main'
permissions:
contents: write
packages: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.source_branch || github.ref }}
submodules: recursive
- name: Check if should be published
if: ${{ github.event_name != 'workflow_dispatch' && !contains(github.event.head_commit.message, '[pub]') }}
run: |
echo "[pub] string is missing in commit message, skipping ..."
exit 0
- name: Publish
id: pub
if: ${{ github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, '[pub]') }}
run: |
CGO_ENABLED=0 \
go build -trimpath -ldflags="-s -w" -o main
if ldd main 2>&1 | grep -vq "not a dynamic executable"; then
echo "ERROR: binary is dynamically linked"
ldd main || true
exit 1
fi
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 \
go build -trimpath -ldflags="-s -w" -o main.exe
echo "exists=true" >> $GITHUB_OUTPUT
- name: Create tag
id: newtag
if: steps.pub.outputs.exists == 'true'
run: |
echo "::group::Version overview"
VERSION=$(awk '/^## /{print $2; exit}' CHANGELOG.md)
BODY=$(awk '/^## /{if (seen++) exit} seen' CHANGELOG.md | tail -n +2)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "body<<EOF" >> $GITHUB_OUTPUT
echo "$BODY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "::endgroup::"
TAG="$VERSION"
echo "::group::New tag created"
echo "tag=$TAG" >> $GITHUB_OUTPUT
git tag $TAG
git push origin $TAG || true
echo "::endgroup::"
- name: Create release
id: crelease
if: steps.pub.outputs.exists == 'true'
uses: actions/create-release@v1
with:
tag_name: ${{ steps.newtag.outputs.version }}
release_name: ${{ steps.newtag.outputs.version }}
body: ${{ steps.newtag.outputs.body }}
env:
GITHUB_TOKEN: ${{ secrets._TOKEN }}
- name: Upload asset
if: steps.pub.outputs.exists == 'true'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets._TOKEN }}
with:
upload_url: ${{ steps.crelease.outputs.upload_url }}
asset_path: ./main
asset_name: main
asset_content_type: application/octet-stream
- name: Upload asset Win
if: steps.pub.outputs.exists == 'true'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets._TOKEN }}
with:
upload_url: ${{ steps.crelease.outputs.upload_url }}
asset_path: ./main.exe
asset_name: main.exe
asset_content_type: application/octet-stream
- name: Set up Docker Buildx
if: steps.pub.outputs.exists == 'true'
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: steps.pub.outputs.exists == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Normalize repository owner
if: steps.pub.outputs.exists == 'true'
id: normalize
run: |
echo "owner_lc=${GITHUB_REPOSITORY_OWNER,,}" >> "$GITHUB_OUTPUT"
- name: Build and push Docker image
if: steps.pub.outputs.exists == 'true'
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64
tags: |
ghcr.io/${{ steps.normalize.outputs.owner_lc }}/minihttpserver:latest
ghcr.io/${{ steps.normalize.outputs.owner_lc }}/minihttpserver:${{ steps.newtag.outputs.version }}
build-args: |
PACKAGE_TAG=${{ steps.newtag.outputs.version }}