-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (130 loc) · 5.42 KB
/
create-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
149
150
151
name: Create Release
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
container:
image: fedora:34
steps:
- name: Install Git
run: dnf install git -y
- name: Checkout the repository
uses: actions/checkout@v2
with:
ref: 'main'
fetch-depth: '0'
- name: Get short commit hash
id: hash
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Get the semver
id: semver
run: echo -n "::set-output name=semver::" && grep "version = " Cargo.toml | cut -d '"' -f 2
- name: Check if semver changed
id: semver_change
run: git --no-pager log -G "version =" --pretty=format:"%h" ./Cargo.toml | grep `git rev-parse --short HEAD` &>/dev/null && echo "::set-output name=changed::true" || echo "::set-output name=changed::false"
- name: Log if semver changed
id: semver_change_test
run: git --no-pager log -G "version =" --pretty=format:"%h" ./Cargo.toml | grep `git rev-parse --short HEAD` &>/dev/null && echo "changed" || echo "not changed"
- name: Cache Cargo registry
uses: actions/cache@v1
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-stable-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-stable-cargo-registry-
- name: Cache Cargo index
uses: actions/cache@v1
with:
path: ~/.cargo/git
key: ${{ runner.os }}-stable-cargo-index-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-stable-cargo-index-
- name: Cache Cargo build
uses: actions/cache@v1
with:
path: target/debug
key: ${{ runner.os }}-stable-debug-target-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-stable-debug-target-
- name: Install Rust
uses: actions-rs/toolchain@v1
if: steps.semver_change.outputs.changed == 'true'
with:
toolchain: stable
- name: Setup RPM tools
if: steps.semver_change.outputs.changed == 'true'
run: "dnf install rpmdevtools gcc copr-cli -y && echo '%_topdir %(echo $PWD)/rpmbuild' > $HOME/.rpmmacros && rpmdev-setuptree"
working-directory: build
- name: Update the Semver in the RPM Spec
if: steps.semver_change.outputs.changed == 'true'
run: 'sed -i -e "s/Version:.*/Version: $VERSION/g" build/SPECS/ractl.spec'
env:
VERSION: ${{ steps.semver.outputs.semver }}
- name: Build ractl
uses: actions-rs/cargo@v1
if: steps.semver_change.outputs.changed == 'true'
with:
command: build
args: --release --all-features
- name: Compile RPM
if: steps.semver_change.outputs.changed == 'true'
run: ./build.sh
working-directory: build
env:
VERSION: ${{ steps.semver.outputs.semver }}
#- name: Create Sentry release
# if: steps.semver_change.outputs.changed == 'true'
# uses: getsentry/action-release@v1
# with:
# version: ${{ steps.semver.outputs.semver }}
# env:
# SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
# SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
# SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
- name: Create Release
if: steps.semver_change.outputs.changed == 'true'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.semver.outputs.semver }}
release_name: Release ${{ steps.semver.outputs.semver }}
body: ${{ github.event.head_commit.message }}
draft: false
prerelease: false
- name: Upload Release Asset - Binary
if: steps.semver_change.outputs.changed == 'true'
id: upload-release-asset-binary
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./target/release/ractl
asset_name: ractl
asset_content_type: application/octet-stream
- name: Upload Release Asset - RPM
if: steps.semver_change.outputs.changed == 'true'
id: upload-release-asset-rpm
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./build/rpmbuild/RPMS/x86_64/ractl-${{ steps.semver.outputs.semver }}-1.x86_64.rpm
asset_name: ractl-${{ steps.semver.outputs.semver }}-1.x86_64.rpm
asset_content_type: application/octet-stream
- name: Login to COPR
if: steps.semver_change.outputs.changed == 'true'
run: 'mkdir ~/.config && printf "[copr-cli]\nlogin = $LOGIN\nusername = $USERNAME\ntoken = $TOKEN\ncopr_url = https://copr.fedorainfracloud.org" > ~/.config/copr'
env:
LOGIN: ${{ secrets.COPR_LOGIN }}
USERNAME: ${{ secrets.COPR_USERNAME }}
TOKEN: ${{ secrets.COPR_TOKEN }}
- name: Upload to COPR
if: steps.semver_change.outputs.changed == 'true'
run: copr-cli build ractl ./build/rpmbuild/SRPMS/ractl-${{ steps.semver.outputs.semver }}-1.src.rpm