-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (145 loc) · 6.32 KB
/
ci.yaml
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
---
name: "Build & Test"
on: [push]
jobs:
set-vars:
name: "Set workflow variables"
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.check_tag.outputs.match }}
steps:
- name: Determine release tag
id: check_tag
run: |
echo "event.ref: ${{ github.event.ref }}"
echo "ref_name: ${{ github.ref_name }}"
echo "ref: ${{ github.ref }}"
if [[ ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "match=true" >> $GITHUB_OUTPUT
echo "Setting check_tag to true"
else
echo "match=false" >> $GITHUB_OUTPUT
echo "Setting check_tag to false"
fi
static-analysis:
needs: set-vars
name: Run static analysis
runs-on: ubuntu-latest
env:
BREADLOG_PKG_URL: "https://github.com/jamesmistry/breadlog/releases/download/v0.4.0/breadlog-package-linux_x86-64.tar.gz"
steps:
- name: Setup | Checkout
uses: actions/checkout@v3
- name: Setup | Prerequisites
run: "sudo bash -c 'apt update && DEBIAN_FRONTEND=noninteractive apt install -y curl'"
- name: Setup | Breadlog
run: 'curl --proto "=https" -LsSf "${BREADLOG_PKG_URL}" | sudo tar -xz -C /'
- name: Breadlog Check | App
run: "breadlog -c ./Breadlog.yaml --check"
- name: Setup | Rust
run: "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y"
- name: Setup | Rust Nightly
run: "rustup install nightly && rustup default nightly"
- name: Setup | Code Formatter
run: "rustup update && rustup component add rustfmt"
- name: Setup | Linter
run: "rustup update && rustup component add clippy"
- name: Code Format Check | App
run: "cargo +nightly fmt -- --check --config-path ./"
- name: Lint | App
run: "cargo clippy -- -A 'clippy::empty-docs' -D warnings"
build:
needs: [static-analysis, set-vars]
name: Build and run tests
# Provides glibc 2.31
runs-on: ubuntu-20.04
steps:
- name: Setup | Checkout
uses: actions/checkout@v3
- name: Setup | Prerequisites
run: "sudo bash -c 'apt update && DEBIAN_FRONTEND=noninteractive apt install -y curl'"
- name: Setup | Rust
run: "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y"
- name: Setup | Rust Nightly
run: "rustup install nightly && rustup default nightly"
- name: Setup | LLVM Tooling
run: "rustup component add llvm-tools-preview --toolchain nightly"
- name: Setup | LLVM helper
run: "cargo install cargo-binutils && cargo install cargo-llvm-cov"
- name: Tests | App
run: './.github/workflows/test_with_coverage.bash "$(pwd)" &> ./test_coverage_report.txt && cat ./test_coverage_report.txt'
- name: Clean artifacts from test | App
run: 'rm -rf ./target/*'
- name: Create build environment | App
run: "docker build --file build.Dockerfile -t breadlog:build ./"
- name: Build | App
run: "docker run -e 'REPO_DIR=/var/repo' --mount type=bind,source='./',target='/repo' breadlog:build"
- name: Store code coverage report | App
uses: actions/upload-artifact@v3
with:
name: test_coverage_report
path: test_coverage_report.txt
retention-days: 7
- name: Store debug output | App
uses: actions/upload-artifact@v3
with:
name: breadlog-debug
path: target/debug/breadlog
retention-days: 7
- name: Store release output | App
uses: actions/upload-artifact@v3
with:
name: breadlog-release
path: target/release/breadlog
retention-days: 7
- name: Build package | App
run: 'BREADLOG_TMP="$(mktemp -d)"; mkdir -p "${BREADLOG_TMP}/usr/bin" && cp target/release/breadlog "${BREADLOG_TMP}/usr/bin/breadlog" && tar -C "${BREADLOG_TMP}" -czf /tmp/breadlog_package.tar.gz usr'
- name: Upload package artifact | App
uses: actions/upload-artifact@v3
with:
name: breadlog-package
path: /tmp/breadlog_package.tar.gz
upload-assets:
# This job will only run on a release tag, which will have been created by
# release-please along with a GitHub release. A GitHub release associated
# with the tag is therefore guaranteed to exist before this job runs,
# providing a location to upload the release artifacts.
#
# Note that there is a race condition between this workflow being triggered
# by release-please pushing a tag and creating the GH release, but given the
# other jobs in the workflow it is safe to assume a GH release will have
# been created in time.
#
# 2 packages with identical content but different names are uploaded: one
# is for manual download and contains the release version in the name
# while the other is for downloading from within user CI pipelines and
# doesn't contain the release version in the name. This allows CI pipelines
# to easily download the latest package from a single, consistent URL.
needs: [set-vars, build]
env:
USER_PACKAGE_NAME: "/tmp/breadlog-package-${{ github.ref_name }}-linux_x86-64.tar.gz"
CI_PACKAGE_NAME: "/tmp/breadlog-package-linux_x86-64.tar.gz"
PACKAGE_HASH_NAME: "/tmp/breadlog-package-linux_x86-64.sha256"
name: Upload release assets
if: needs.set-vars.outputs.release_tag == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: breadlog-package
- name: Store package hash | Release
run: 'sha256sum ./breadlog_package.tar.gz | cut -d " " -f 1 > "${PACKAGE_HASH_NAME}"'
- name: Create user package | Release
run: 'cp "./breadlog_package.tar.gz" "${USER_PACKAGE_NAME}"'
- name: Create CI package | Release
run: 'cp "./breadlog_package.tar.gz" "${CI_PACKAGE_NAME}"'
- name: Auth GH CLI | Release
run: 'echo "${{ secrets.BREADLOG_RELEASE_PAT }}" | gh auth login --with-token'
- name: Upload user release artifact | Release
run: 'gh release upload "${{github.ref_name}}" "${USER_PACKAGE_NAME}#Installer archive (Linux x86-64)"'
- name: Upload CI release artifact | Release
run: 'gh release upload "${{github.ref_name}}" "${CI_PACKAGE_NAME}"'
- name: Upload package hash | Release
run: 'gh release upload "${{github.ref_name}}" "${PACKAGE_HASH_NAME}#Installer hash (Linux x86-64)"'