159 lines (146 loc) · 4.96 KB
/
build.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
name: Build
on:
push:
#branches: [ master ]
tags:
- 'v*'
#pull_request:
#branches: [ master ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Checkout
# Setup software (NodeJS, Docker)
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Use Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Caches for npm / cargo / rustup
- name: Cache Node Modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Cache Rust Dependencies
uses: actions/cache@v2
with:
path: target
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.OS }}-rust-
- name: Cache RustUp Toolchains
uses: actions/cache@v2
with:
path: ~/.rustup
key: ${{ runner.os }}-rustup
- name: Cache Cargo
uses: actions/cache@v2
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.OS }}-cargo-
# Build frontend / Angular app
- run: cd secretnote-fe && npm ci
name: Install Frontend Dependencies
- run: cd secretnote-fe && npm run build
name: Build Frontend
# Build server / Rust part
- name: Install Rust Build Dependencies
run: sudo apt-get install -y musl-tools gcc-mingw-w64-x86-64
- name: RustUp
run: rustup target add x86_64-unknown-linux-musl && rustup target add x86_64-pc-windows-gnu
- name: Build Server (Linux/amd64)
run: cargo build --release --target x86_64-unknown-linux-musl
- name: Build Server (Windows/amd64)
run: cargo build --release --target x86_64-pc-windows-gnu
# Upload build results (Linux)
- run: |
cp target/x86_64-unknown-linux-musl/release/secretnote ./
cp target/x86_64-unknown-linux-musl/release/secretnote-statistics-exporter ./
cp target/x86_64-unknown-linux-musl/release/secretnote-cli ./
strip ./secretnote
strip ./secretnote-statistics-exporter
strip ./secretnote-cli
echo '/secretnote-fe/node_modules' >> .dockerignore
name: "Prepare (Linux/amd64)"
- name: Upload (Linux/amd64)
uses: actions/upload-artifact@v2
with:
name: "SecretNote for Linux amd64"
path: |
./fe
./secretnote
./secretnote-statistics-exporter
./secretnote-cli
retention-days: 365
- name: Upload CLI (Linux/amd64)
uses: actions/upload-artifact@v2
with:
name: "SecretNote CLI for Linux amd64"
path: |
./secretnote-cli
retention-days: 365
# Docker
- name: Build and push docker image (Linux/amd64)
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./CI.Dockerfile
platforms: linux/amd64
push: true
tags: markusbauer/secretnote:latest
# Upload build results (Windows)
- run: |
cp target/x86_64-pc-windows-gnu/release/secretnote.exe ./
cp target/x86_64-pc-windows-gnu/release/secretnote-cli.exe ./
name: "Prepare (Windows/x64)"
- name: Upload (Windows)
uses: actions/upload-artifact@v2
with:
name: "SecretNote for Windows x64"
path: |
./fe
./secretnote.exe
./secretnote-cli.exe
retention-days: 365
- name: Upload CLI (Windows)
uses: actions/upload-artifact@v2
with:
name: "SecretNote CLI for Windows x64"
path: |
./secretnote-cli.exe
retention-days: 365
# Create a release
- name: Create Release
id: create_release
uses: actions/create-release@v1.1.4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
# The name of the tag. This should come from the webhook payload, `github.GITHUB_REF` when a user pushes a new tag
tag_name: ${{ github.ref }}
# The name of the release. For example, `Release v1.0.1`
release_name: Release ${{ github.ref }}
# Text describing the contents of the tag.
body: Automatic release
# Path to file with information about the tag.
#body_path: # optional
# `true` to create a draft (unpublished) release, `false` to create a published one. Default: `false`
draft: true
# `true` to identify the release as a prerelease. `false` to identify the release as a full release. Default: `false`
prerelease: false