-
Notifications
You must be signed in to change notification settings - Fork 2
186 lines (181 loc) · 6.58 KB
/
release-needle.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
name: release-needle
on:
push:
branches:
- main
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.event.repository.name }}
defaults:
run:
shell: bash
working-directory: needle
jobs:
release-please:
runs-on: ubuntu-latest
outputs:
# NOTE: No idea why release-please is running in "manifest" mode, but it is...
tag_name: ${{ steps['release']['outputs']['needle--tag_name'] }}
release_created: ${{ steps['release']['outputs']['needle--release_created'] }}
steps:
# Copied from: https://github.com/andrey-yantsen/plex-api.rs/blob/main/.github/workflows/release.yml#L18
- uses: google-github-actions/release-please-action@v3
id: release
with:
path: needle
release-type: rust
bump-minor-pre-major: true
bump-patch-for-minor-pre-major: true
changelog-types: |
[{"type":"feat","section":"Features","hidden":false},
{"type":"fix","section":"Bug Fixes","hidden":false},
{"type":"chore","section":"Miscellaneous","hidden":false},
{"type":"test","section":"Tests","hidden":true},
{"type":"ci","section":"Continuous Integration","hidden":true},
{"type":"doc","section":"Documentation","hidden":true},
{"type":"refactor","section":"Code Refactoring","hidden":true}]
linux:
runs-on: ubuntu-latest
needs: release-please
if: needs.release-please.outputs.release_created
env:
TAG_NAME: ${{ needs.release-please.outputs.tag_name }}
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- name: Install dependencies
run: |
sudo apt-get install \
pkg-config \
cmake \
libclang-dev \
libfftw3-dev \
libavutil-dev \
libavformat-dev \
libswresample-dev \
libavcodec-dev
- name: Build release version
run: cargo build -v --release
- name: Compress binary
run: cd target/release && tar cvzf needle-$TAG_NAME-linux-amd64.tar.gz needle
- name: Upload binary to the release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.TAG_NAME }}
files: needle/target/release/*.tar.gz
macos:
runs-on: macos-latest
needs: release-please
if: needs.release-please.outputs.release_created
env:
TAG_NAME: ${{ needs.release-please.outputs.tag_name }}
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- name: Install dependencies
run: brew install ffmpeg
- name: Build release version
run: cargo build -v --release
- name: Compress binary
run: cd target/release && tar cvzf needle-$TAG_NAME-macos-amd64.tar.gz needle
- name: Upload binary to the release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.TAG_NAME }}
files: needle/target/release/*.tar.gz
windows:
runs-on: windows-latest
needs: release-please
if: needs.release-please.outputs.release_created
env:
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/vcpkg-bincache
TAG_NAME: ${{ needs.release-please.outputs.tag_name }}
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- name: "Create directory '${{ env.VCPKG_DEFAULT_BINARY_CACHE }}'"
run: mkdir -p $VCPKG_DEFAULT_BINARY_CACHE
shell: bash
- name: Install cargo-vcpkg
run: cargo install cargo-vcpkg
# Restore both vcpkg and its artifacts from the GH cache service.
# Taken from here: https://github.com/lukka/CppCMakeVcpkgTemplate/blob/main/.github/workflows/hosted-pure-workflow.yml
- name: Restore vcpkg and its artifacts.
uses: actions/cache@v3
env:
cache-name: cache-vcpkg
with:
path: |
${{ env.VCPKG_ROOT }}
!${{ env.VCPKG_ROOT }}/buildtrees
!${{ env.VCPKG_ROOT }}/packages
!${{ env.VCPKG_ROOT }}/downloads
!${{ env.VCPKG_ROOT }}/installed
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles( 'needle/Cargo.lock' ) }}
- name: Install dependencies
run: cargo vcpkg --verbose build
shell: bash
- name: Build release version
run: cargo build -v --release --features static
- name: Compress binary (using Powershell)
run: Compress-Archive -Path "$env:GITHUB_WORKSPACE\needle\target\release\needle.exe" -DestinationPath "$env:GITHUB_WORKSPACE\needle-$env:TAG_NAME-windows-amd64.zip"
shell: pwsh
- name: Upload binary to the release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.TAG_NAME }}
files: "*.zip"
publish-crate:
runs-on: ubuntu-latest
needs:
- release-please
- linux
- macos
- windows
if: needs.release-please.outputs.release_created
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get install \
libfftw3-dev \
libavutil-dev \
libavformat-dev \
libswresample-dev \
libavcodec-dev
- name: Publish needle-rs to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
build-and-push-tagged-image:
runs-on: ubuntu-latest
needs:
- release-please
if: needs.release-please.outputs.release_created
env:
TAG_NAME: ${{ needs.release-please.outputs.tag_name }}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
- name: Log in to GH container registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ env.TAG_NAME }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
VERSION=$(echo "${{ env.TAG_NAME }}" | sed -e 's/^v//')
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION