@@ -3,10 +3,14 @@ name: Build
3
3
on :
4
4
workflow_dispatch :
5
5
push :
6
+ tags : [v*]
7
+ branches : [main]
6
8
paths-ignore :
7
9
- ' **.md'
8
10
pull_request :
9
11
branches : [main]
12
+ release :
13
+ types : [published]
10
14
11
15
jobs :
12
16
build-chisel :
@@ -30,17 +34,82 @@ jobs:
30
34
machine_arch : ' S/390'
31
35
steps :
32
36
- uses : actions/checkout@v3
37
+ with :
38
+ fetch-depth : 0
39
+
40
+ # The checkout action in previous step overwrites annonated tag
41
+ # with lightweight tags breaking ``git describe``
42
+ # See https://github.com/actions/checkout/issues/882
43
+ # and https://github.com/actions/checkout/issues/290
44
+ # The following step is a workaround to restore the latest tag
45
+ # to it's original state.
46
+ - name : Restore (annonated) tag
47
+ run : git fetch --force origin ${GITHUB_REF}:${GITHUB_REF}
48
+ if : ${{ github.ref_type == 'tag' }}
33
49
34
50
- uses : actions/setup-go@v3
35
51
with :
36
52
go-version-file : ' go.mod'
37
53
38
54
- name : Build Chisel for linux/${{ matrix.arch }}
39
- run : GOARCH=${{ matrix.arch }} go build ./cmd/chisel/
55
+ id : build
56
+ env :
57
+ GOOS : " linux"
58
+ GOARCH : ${{ matrix.arch }}
59
+ CGO_ENABLED : " 0"
60
+ run : |
61
+ echo "Generating version file"
62
+ go generate ./cmd/
63
+
64
+ echo "Building for $GOOS $GOARCH"
65
+ go build -trimpath -ldflags='-s -w' ./cmd/chisel
66
+
67
+ # Get version via "chisel version" to ensure it matches that exactly
68
+ CHISEL_VERSION=$(GOOS=linux GOARCH=amd64 go run ./cmd/chisel version)
69
+ echo "Version: $CHISEL_VERSION"
70
+
71
+ # Version should not be "unknown"
72
+ [ "$CHISEL_VERSION" != "unknown" ] || exit 1
73
+
74
+ # Share variables with subsequent steps
75
+ echo "CHISEL_VERSION=${CHISEL_VERSION}" >>$GITHUB_OUTPUT
40
76
41
77
- name : Test if is executable
42
78
run : test -x ./chisel
43
79
44
80
- name : Test if binary has the right machine architecture
45
81
run : |
46
82
[ "$(readelf -h chisel | grep 'Machine:' | awk -F' ' '{print $NF}')" == "${{ matrix.machine_arch }}" ]
83
+
84
+ - name : Create archive
85
+ id : archive
86
+ env :
87
+ GOOS : " linux"
88
+ GOARCH : ${{ matrix.arch }}
89
+ CHISEL_VERSION : ${{ steps.build.outputs.CHISEL_VERSION }}
90
+ run : |
91
+ ARCHIVE_FILE=chisel_${CHISEL_VERSION}_${GOOS}_${GOARCH}.tar.gz
92
+ echo "Creating archive $ARCHIVE_FILE"
93
+
94
+ mkdir -p dist/build
95
+ cp chisel LICENSE README.md dist/build
96
+ find dist/build -printf "%P\n" | tar -czf dist/$ARCHIVE_FILE --no-recursion -C dist/build -T -
97
+
98
+ # Share variables with subsequent steps
99
+ echo "ARCHIVE_FILE=${ARCHIVE_FILE}" >>$GITHUB_OUTPUT
100
+
101
+ - name : Upload archive as Actions artifact
102
+ uses : actions/upload-artifact@v3
103
+ with :
104
+ name : ${{ steps.archive.outputs.ARCHIVE_FILE }}
105
+ path : dist/${{ steps.archive.outputs.ARCHIVE_FILE }}
106
+
107
+ - name : Upload archive to release
108
+ env :
109
+ CHISEL_VERSION : ${{ steps.build.outputs.CHISEL_VERSION }}
110
+ ARCHIVE_FILE : ${{ steps.archive.outputs.ARCHIVE_FILE }}
111
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
112
+ if : ${{ github.event_name == 'release' }}
113
+ run : |
114
+ echo "Uploading $ARCHIVE_FILE to release $CHISEL_VERSION"
115
+ gh release upload $CHISEL_VERSION dist/$ARCHIVE_FILE
0 commit comments