This repository has been archived by the owner on Jul 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
148 lines (118 loc) · 4.47 KB
/
release.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
# Source of this pipeline code: https://github.com/paskausks/rust-bin-github-workflows
# MIT License - Copyright (c) 2019 Rihards Paskausks
# Modified by
# Copyright (c) 2024 Malte Janz
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
name: Create and deploy release
env:
# Could, potentially automatically parse
# the bin name, but let's do it automatically for now.
RELEASE_BIN: sw-sync-cli
# Space separated paths to include in the archive.
# Start relative paths with a dot if you don't want
# paths to be preserved. Use "/" as a delimiter.
RELEASE_ADDS: README.md LICENSE
# Name of the docker image
CONTAINER_IMG_NAME: "maltejanz/sw-sync-cli"
jobs:
tag_version:
name: Get the version from tag
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.VERSION }}
steps:
- name: Save version from tag
id: get_version
shell: bash
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
build:
name: Build artifacts
needs: [tag_version]
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- build: x86_64-unknown-linux-gnu
os: ubuntu-latest
type: application/gzip
output_ending: .tar.gz
- build: x86_64-apple-darwin
os: macos-latest
type: application/gzip
output_ending: .tar.gz
- build: aarch64-apple-darwin
os: macos-14 # m1 runner
type: application/gzip
output_ending: .tar.gz
- build: x86_64-pc-windows-msvc
os: windows-latest
type: application/zip
output_ending: .zip
steps:
- uses: actions/checkout@v4
- name: Install latest stable Rust version
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Final cargo test
run: cargo test --verbose --all-features
- name: Run cargo build
run: cargo build --release --verbose
- name: Create artifact directory
run: mkdir artifacts
- name: Create archive for Windows
run: 7z a -tzip ./artifacts/${{ env.RELEASE_BIN }}-${{ needs.tag_version.outputs.version }}-${{ matrix.build }}${{ matrix.output_ending }} ./target/release/${{ env.RELEASE_BIN }}.exe ${{ env.RELEASE_ADDS }}
if: matrix.os == 'windows-latest'
- name: Create archive for Linux
run: 7z a -ttar -so -an ./target/release/${{ env.RELEASE_BIN }} ${{ env.RELEASE_ADDS }} | 7z a -tgzip -si ./artifacts/${{ env.RELEASE_BIN }}-${{ needs.tag_version.outputs.version }}-${{ matrix.build }}${{ matrix.output_ending }}
if: matrix.os == 'ubuntu-latest'
# should not be needed anymore
#- name: Install p7zip on MacOS
# 7Zip not available on MacOS, install p7zip via homebrew.
# run: brew install p7zip
# if: matrix.os == 'macos-latest' || matrix.os == 'macos-14'
- name: Create archive for MacOS
run: 7z a -ttar -so -an ./target/release/${{ env.RELEASE_BIN }} ${{ env.RELEASE_ADDS }} | 7z a -tgzip -si ./artifacts/${{ env.RELEASE_BIN }}-${{ needs.tag_version.outputs.version }}-${{ matrix.build }}${{ matrix.output_ending }}
if: matrix.os == 'macos-latest' || matrix.os == 'macos-14'
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
path: artifacts/*
name: executable-${{ matrix.build }}
if-no-files-found: error
github_draft_release:
name: Create GitHub draft release
needs: [tag_version, build]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: artifacts
pattern: executable-*
merge-multiple: true
- name: Create draft release
id: create_release
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ github.ref }}
name: Release ${{ needs.tag_version.outputs.version }}
draft: true
prerelease: false
files: |
artifacts/*
publish_crate:
name: Publish to crates.io
needs: [tag_version, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install latest stable Rust version
uses: dtolnay/rust-toolchain@stable
- name: Publish sw-sync-cli
env:
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}
run: cargo publish --token ${CRATES_TOKEN}