Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit 842e24f

Browse files
author
Paulo Gomes
authored
Merge pull request #28 from somtochiama/supply-chain
Improve supply chain security
2 parents 99f2a25 + 7ff667d commit 842e24f

File tree

5 files changed

+122
-66
lines changed

5 files changed

+122
-66
lines changed

.github/workflows/build.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414

1515
permissions:
1616
packages: write # needed for ghcr access
17+
id-token: write # needed for keyless signing
1718

1819
jobs:
1920

@@ -48,6 +49,8 @@ jobs:
4849
uses: actions/checkout@v2
4950
- name: Unshallow
5051
run: git fetch --prune --unshallow
52+
- name: Setup Cosign
53+
uses: sigstore/cosign-installer@main
5154
- name: Set up QEMU
5255
id: qemu
5356
uses: docker/setup-qemu-action@v1
@@ -148,6 +151,16 @@ jobs:
148151
tags: ${{ steps.meta_libgit2_all.outputs.tags }}
149152
labels: ${{ steps.meta_libgit2_all.outputs.labels }}
150153
cache-from: type=local,src=/tmp/.buildx-cache
154+
- name: Sign images
155+
env:
156+
COSIGN_EXPERIMENTAL: 1
157+
run: |
158+
array=($(echo ${{ steps.meta_libgit2_all.outputs.tags }} | tr '\n' " "))
159+
for image in "${array[@]}"
160+
do
161+
echo "Signing $image"
162+
cosign sign $image
163+
done
151164
152165
- name: Compose release candidate metadata - golang-with-libgit2-only
153166
id: meta_libgit2_only
@@ -174,3 +187,13 @@ jobs:
174187
tags: ${{ steps.meta_libgit2_only.outputs.tags }}
175188
labels: ${{ steps.meta_libgit2_only.outputs.labels }}
176189
cache-from: type=local,src=/tmp/.buildx-cache
190+
- name: Sign images
191+
env:
192+
COSIGN_EXPERIMENTAL: 1
193+
run: |
194+
array=($(echo ${{ steps.meta_libgit2_all.outputs.tags }} | tr '\n' " "))
195+
for element in "${array[@]}"
196+
do
197+
echo ${element}
198+
cosign sign $element
199+
done

.github/workflows/release.yaml

+36-66
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,12 @@ on:
1515

1616
permissions:
1717
contents: write # needed to write releases
18+
id-token: write # needed for keyless signing
1819

1920
jobs:
2021

21-
github_release:
22-
runs-on: ubuntu-latest
23-
outputs:
24-
release_upload_url: ${{ steps.create_release.outputs.upload_url }}
25-
steps:
26-
- name: Prepare
27-
id: prep
28-
run: |
29-
VERSION="${{ github.event.inputs.tag }}-${GITHUB_SHA::8}"
30-
if [[ $GITHUB_REF == refs/tags/* ]]; then
31-
VERSION=${GITHUB_REF/refs\/tags\//}
32-
fi
33-
echo ::set-output name=VERSION::${VERSION}
34-
- name: Create Release
35-
id: create_release
36-
uses: actions/create-release@v1
37-
env:
38-
GITHUB_TOKEN: ${{ github.token }}
39-
with:
40-
release_name: ${{ steps.prep.outputs.VERSION }}
41-
tag_name: ${{ steps.prep.outputs.VERSION }}
42-
draft: false
43-
prerelease: true
44-
4522
linux-amd64-release:
4623
runs-on: ubuntu-latest
47-
needs: github_release
4824
steps:
4925
- name: Checkout
5026
uses: actions/checkout@v2
@@ -62,16 +38,6 @@ jobs:
6238
6339
tar -zcvf linux-x86_64-libgit2-all-libs.tar.gz libgit2-linux-libgit2-all
6440
rm -rf ${GITHUB_WORKSPACE}/build ${GITHUB_WORKSPACE}/libgit2
65-
- name: Upload Release Asset
66-
id: upload-release-asset-libgit2-all
67-
uses: actions/upload-release-asset@v1
68-
env:
69-
GITHUB_TOKEN: ${{ github.token }}
70-
with:
71-
upload_url: ${{ needs.github_release.outputs.release_upload_url }}
72-
asset_path: ./linux-x86_64-libgit2-all-libs.tar.gz
73-
asset_name: linux-x86_64-libgit2-all-libs.tar.gz
74-
asset_content_type: application/gzip
7541
7642
- name: Build static libraries - libgit2 only
7743
run: |
@@ -85,16 +51,11 @@ jobs:
8551
8652
tar -zcvf linux-x86_64-libgit2-only-lib.tar.gz libgit2-linux-libgit2-only
8753
rm -rf ${GITHUB_WORKSPACE}/build ${GITHUB_WORKSPACE}/libgit2
88-
- name: Upload Release Asset
89-
id: upload-release-asset-libgit2-only
90-
uses: actions/upload-release-asset@v1
91-
env:
92-
GITHUB_TOKEN: ${{ github.token }}
54+
- uses: actions/upload-artifact@v3
9355
with:
94-
upload_url: ${{ needs.github_release.outputs.release_upload_url }}
95-
asset_path: ./linux-x86_64-libgit2-only-lib.tar.gz
96-
asset_name: linux-x86_64-libgit2-only-lib.tar.gz
97-
asset_content_type: application/gzip
56+
name: release-artifact
57+
path: '*.tar.gz'
58+
if-no-files-found: error
9859

9960
darwin-release:
10061
# This job builds and releases "universal libraries" that are
@@ -108,7 +69,6 @@ jobs:
10869
# of testing, GitHub's macos-10.15 did not seem to.
10970
# Cross-compiling to arm64 on that runner consistently failed.
11071
runs-on: macos-11
111-
needs: github_release
11272
steps:
11373
- name: Checkout
11474
uses: actions/checkout@v2
@@ -156,16 +116,6 @@ jobs:
156116
rm -rf ${GITHUB_WORKSPACE}/build ${GITHUB_WORKSPACE}/libgit2
157117
env:
158118
MACOSX_DEPLOYMENT_TARGET: 10.15
159-
- name: Upload Release Asset
160-
id: upload-release-asset-libgit2-all
161-
uses: actions/upload-release-asset@v1
162-
env:
163-
GITHUB_TOKEN: ${{ github.token }}
164-
with:
165-
upload_url: ${{ needs.github_release.outputs.release_upload_url }}
166-
asset_path: ./darwin-libgit2-all-libs.tar.gz
167-
asset_name: darwin-libgit2-all-libs.tar.gz
168-
asset_content_type: application/gzip
169119

170120
- name: Build universal static libraries for Darwin - libgit2 only
171121
run: |
@@ -179,9 +129,8 @@ jobs:
179129
CMAKE_APPLE_SILICON_PROCESSOR=arm64 \
180130
./hack/static.sh build_libgit2_only
181131
182-
mkdir -p ./libgit2-darwin-libgit2-only
132+
mkdir -p ./libgit2-darwin-libgit2-only/lib
183133
mv ${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64/include ./libgit2-darwin-libgit2-only/
184-
mv ${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64/lib ./libgit2-darwin-libgit2-only/
185134
186135
libtool -static -o ./libgit2-darwin-libgit2-only/lib/libgit2.a \
187136
${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64/lib/libgit2.a \
@@ -191,13 +140,34 @@ jobs:
191140
rm -rf ${GITHUB_WORKSPACE}/build ${GITHUB_WORKSPACE}/libgit2
192141
env:
193142
MACOSX_DEPLOYMENT_TARGET: 10.15
194-
- name: Upload Release Asset
195-
id: upload-release-asset-libgit2-only
196-
uses: actions/upload-release-asset@v1
197-
env:
198-
GITHUB_TOKEN: ${{ github.token }}
143+
- uses: actions/upload-artifact@v3
144+
with:
145+
name: release-artifact
146+
path: '*.tar.gz'
147+
if-no-files-found: error
148+
149+
goreleaser:
150+
runs-on: ubuntu-latest
151+
needs: [linux-amd64-release, darwin-release]
152+
if: ${{ always() && contains(join(needs.*.result, ','), 'success') }}
153+
steps:
154+
- uses: actions/checkout@v2
155+
with:
156+
fetch-depth: 0
157+
- uses: actions/setup-go@v2
158+
with:
159+
go-version: 1.17.x
160+
- name: Setup Cosign
161+
uses: sigstore/cosign-installer@main
162+
- name: Setup Syft
163+
uses: anchore/sbom-action/download-syft@v0
164+
- name: Download Files
165+
uses: actions/download-artifact@v3
199166
with:
200-
upload_url: ${{ needs.github_release.outputs.release_upload_url }}
201-
asset_path: ./darwin-libs-libgit2-only.tar.gz
202-
asset_name: darwin-libs-libgit2-only.tar.gz
203-
asset_content_type: application/gzip
167+
name: release-artifact
168+
- uses: goreleaser/goreleaser-action@v2
169+
with:
170+
version: latest
171+
args: release --rm-dist
172+
env:
173+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
build/
22
vendor/
3+
4+
# Built library files
5+
*.tar.gz

.goreleaser.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
project_name: golang-with-libgit2
2+
3+
builds:
4+
- skip: true
5+
6+
release:
7+
prerelease: auto
8+
extra_files:
9+
- glob: '*.tar.gz'
10+
11+
changelog:
12+
use: github-native
13+
14+
sboms:
15+
- artifacts: archive
16+
- id: source
17+
artifacts: source
18+
documents:
19+
- "{{ .ProjectName }}_{{ .Version }}_sbom.spdx.json"
20+
21+
checksum:
22+
name_template: 'checksums.txt'
23+
extra_files:
24+
- glob: '*.tar.gz'
25+
26+
source:
27+
enabled: true
28+
29+
signs:
30+
- cmd: cosign
31+
env:
32+
- COSIGN_EXPERIMENTAL=1
33+
certificate: '${artifact}.pem'
34+
args:
35+
- sign-blob
36+
- '--output-certificate=${certificate}'
37+
- '--output-signature=${signature}'
38+
- '${artifact}'
39+
artifacts: checksum
40+
output: true

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,23 @@ $ readelf -h /usr/local/aarch64-alpine-linux-musl/lib/libz.a | grep Machine | so
139139
[libssh2-1-misconfiguration]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=668271
140140
[mbedtls-ed25519]: https://github.com/ARMmbed/mbedtls/issues/2452
141141
[libgit2-5750]: https://github.com/libgit2/libgit2/pull/5750
142+
143+
## To verify artefacts
144+
145+
Download the following files from the releases section:
146+
1. checksum.txt
147+
2. checksum.txt.pem
148+
3. checksum.txt.sig
149+
4. The compressed library files
150+
151+
You can verify that the `checksum.txt` wasn't tampered with using `cosign` and the downloaded certificate and signature.
152+
153+
```
154+
cosign verify-blob --cert checksums.txt.pem --signature checksums.txt.sig checksums.txt
155+
```
156+
157+
Verify the hashes of the other files using `checksum.txt`:
158+
159+
```
160+
sha256sum --ignore-missing -c checksums.txt
161+
```

0 commit comments

Comments
 (0)