1
+ # The way this works is the following:
2
+ #
3
+ # The create-release job runs purely to initialize the GitHub release itself
4
+ # and to output upload_url for the following job.
5
+ #
6
+ # The build-release job runs only once create-release is finished. It gets the
7
+ # release upload URL from create-release job outputs, then builds the release
8
+ # executables for each supported platform and attaches them as release assets
9
+ # to the previously created release.
10
+ #
11
+ # The key here is that we create the release only once.
12
+ #
13
+ # Reference:
14
+ # https://eugene-babichenko.github.io/blog/2020/05/09/github-actions-cross-platform-auto-releases/
15
+
16
+ name : post-release
17
+ on :
18
+ push :
19
+ tags :
20
+ - " v*"
21
+
22
+ env :
23
+ BIN_NAME : emo_shiro
24
+ jobs :
25
+ create-release :
26
+ name : emo_shiro
27
+ runs-on : ubuntu-latest
28
+ outputs :
29
+ upload_url : ${{ steps.release.outputs.upload_url }}
30
+ release_version : ${{ env.RELEASE_VERSION }}
31
+ steps :
32
+ - name : Get the release version from the tag
33
+ shell : bash
34
+ if : env.RELEASE_VERSION == ''
35
+ run : |
36
+ # See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027
37
+ echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
38
+ echo "version is: ${{ env.RELEASE_VERSION }}"
39
+ - name : Checkout repository
40
+ uses : actions/checkout@v2
41
+ with :
42
+ fetch-depth : 1
43
+ - name : Generate Release Notes
44
+ run : |
45
+ python3 .github/workflows/release-notes.py --tag ${{ env.RELEASE_VERSION }} --output notes-${{ env.RELEASE_VERSION }}.md
46
+ cat notes-${{ env.RELEASE_VERSION }}.md
47
+ - name : Create GitHub release
48
+ id : release
49
+ uses : actions/create-release@v1
50
+ env :
51
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
52
+ with :
53
+ tag_name : ${{ env.RELEASE_VERSION }}
54
+ release_name : ${{ env.RELEASE_VERSION }}
55
+ body_path : notes-${{ env.RELEASE_VERSION }}.md
56
+ build-release :
57
+ name : build-release
58
+ needs : create-release
59
+ strategy :
60
+ fail-fast : false
61
+ matrix :
62
+ build : [ linux, macos, macos_m1, win-msvc ]
63
+ include :
64
+ - build : linux
65
+ os : ubuntu-latest
66
+ rust : stable
67
+ target : x86_64-unknown-linux-musl
68
+ file : emo_shiro_amd64
69
+ - build : macos
70
+ os : macos-latest
71
+ rust : stable
72
+ target : x86_64-apple-darwin
73
+ file : emo_shiro_darwin
74
+ - build : macos_m1
75
+ os : macos-latest
76
+ rust : stable
77
+ target : aarch64-apple-darwin
78
+ file : emo_shiro_aarch64_darwin
79
+ - build : win-msvc
80
+ os : windows-latest
81
+ rust : stable
82
+ target : i686-pc-windows-msvc
83
+ file : emo_shiro.exe
84
+ runs-on : ${{ matrix.os }}
85
+ steps :
86
+ - name : Checkout repository
87
+ uses : actions/checkout@v2
88
+ with :
89
+ fetch-depth : 1
90
+ - name : Cache
91
+ uses : Swatinem/rust-cache@v1
92
+ - name : Install packages (Ubuntu)
93
+ if : matrix.os == 'ubuntu-latest'
94
+ run : |
95
+ sudo apt-get update
96
+ sudo apt-get install -y --no-install-recommends xz-utils liblz4-tool libssl-dev musl-tools pkg-config
97
+ sed -i -e "s/^version = .*/version = \"`date +'%-Y.%-m.%-d'`\"/" Cargo.toml
98
+ - name : Install packages (Windows)
99
+ if : matrix.os == 'windows-latest'
100
+ shell : bash
101
+ run : |
102
+ choco install llvm openssl
103
+ export CARGO_PKG_VERSION=`date +'%-Y.%-m.%-d'`
104
+ sed -i -e "s/^version = .*/version = \"`date +'%-Y.%-m.%-d'`\"/" Cargo.toml
105
+ echo "CARGO_PKG_VERSION=`date +'%Y.%m.%d'`" >>$GITHUB_ENV
106
+ echo "OPENSSL_DIR=C:\Program Files\OpenSSL-Win64" >>$GITHUB_ENV
107
+ echo "RUSTFLAGS=-C target-feature=+crt-static" >>$GITHUB_ENV
108
+ - name : Install packages (Macos)
109
+ if : matrix.os == 'macos-latest'
110
+ run : |
111
+ sed -i -e "s/^version = .*/version = \"`date +'%-Y.%-m.%-d'`\"/" Cargo.toml
112
+ - name : Install Rust
113
+ uses : actions-rs/toolchain@v1
114
+ with :
115
+ toolchain : ${{ matrix.rust }}
116
+ profile : minimal
117
+ override : true
118
+ target : ${{ matrix.target }}
119
+ - name : Build release binary
120
+ run : cargo build --target ${{ matrix.target }} --verbose --release
121
+ - name : Build archive
122
+ shell : bash
123
+ run : |
124
+ staging="${{ env.BIN_NAME }}_${{ needs.create-release.outputs.release_version }}_${{ matrix.target }}"
125
+ mkdir -p "$staging"
126
+ cp {README.md,LICENSE} "$staging/"
127
+ if [ "${{ matrix.os }}" = "windows-latest" ]; then
128
+ bin_file="target/${{ matrix.target }}/release/${{ env.BIN_NAME }}.exe"
129
+ cp "$bin_file" "$staging/"
130
+ cd "$staging"
131
+ 7z a "../$staging.zip" .
132
+ echo "ASSET=$staging.zip" >> $GITHUB_ENV
133
+ echo "BIN_FILE=$bin_file" >> $GITHUB_ENV
134
+ else
135
+ bin_file="target/${{ matrix.target }}/release/${{ env.BIN_NAME }}"
136
+ strip "$bin_file"
137
+ cp "$bin_file" "$staging/"
138
+ tar czf "$staging.tar.gz" -C "$staging" ${{ env.BIN_NAME }} README.md LICENSE
139
+ echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
140
+ echo "BIN_FILE=$bin_file" >> $GITHUB_ENV
141
+ fi
142
+ - name : Upload release archive
143
+
144
+ env :
145
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
146
+ with :
147
+ upload_url : ${{ needs.create-release.outputs.upload_url }}
148
+ asset_path : ${{ env.ASSET }}
149
+ asset_name : ${{ env.ASSET }}
150
+ asset_content_type : application/octet-stream
151
+ - name : Upload binary to release
152
+ uses : svenstaro/upload-release-action@v1-release
153
+ with :
154
+ repo_token : ${{ secrets.GITHUB_TOKEN }}
155
+ file : ${{ env.BIN_FILE }}
156
+ asset_name : ${{ matrix.file }}
157
+ tag : default
158
+ overwrite : true
0 commit comments