-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (156 loc) · 6.05 KB
/
publish.yaml
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
name: publish_site_release_assets
on:
pull_request:
branches:
- main
types: [closed]
jobs:
setup:
runs-on: ubuntu-latest
# ブランチ名が release/v から始まる場合のみに実行する.
# プルリクエストがマージされた場合のみに実行する.
if: startsWith(github.head_ref, 'release/v') && github.event.pull_request.merged == true
outputs:
appname: totebag
tag: ${{ steps.vars.outputs.tag }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Git Tag name
id: vars
run: |
echo "GITHUB_HEAD_REF: $GITHUB_HEAD_REF (${GITHUB_HEAD_REF##*/v})"
echo "tag=${GITHUB_HEAD_REF##*/v}" >> $GITHUB_OUTPUT
- name: Create release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.vars.outputs.tag }}
name: Release v${{ steps.vars.outputs.tag }}
draft: false
prerelease: false
publish:
runs-on: ${{ matrix.os }}
needs: setup
outputs:
appname: ${{ needs.setup.outputs.appname }}
tag: ${{ needs.setup.outputs.tag }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: aarch64-unknown-linux-musl
artifact_name: ${{ needs.setup.outputs.appname }}
asset_name: ${{ needs.setup.outputs.appname }}-${{ needs.setup.outputs.tag }}_linux_amd64
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
artifact_name: ${{ needs.setup.outputs.appname }}
asset_name: ${{ needs.setup.outputs.appname }}-${{ needs.setup.outputs.tag }}_linux_arm64
# - os: ubuntu-latest
# target: aarch64-pc-windows-gnullvm
# artifact_name: ${{ needs.setup.outputs.appname }}.exe
# asset_name: ${{ needs.setup.outputs.appname }}-${{ needs.setup.outputs.tag }}_windows_amd64
# - os: ubuntu-latest
# target: x86_64-pc-windows-gnu
# artifact_name: ${{ needs.setup.outputs.appname }}.exe
# asset_name: ${{ needs.setup.outputs.appname }}-${{ needs.setup.outputs.tag }}_windows_arm64
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: ${{ needs.setup.outputs.appname }}
asset_name: ${{ needs.setup.outputs.appname }}-${{ needs.setup.outputs.tag }}_darwin_amd64
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: ${{ needs.setup.outputs.appname }}
asset_name: ${{ needs.setup.outputs.appname }}-${{ needs.setup.outputs.tag }}_darwin_arm64
steps:
# initialization
- name: Checkout the project
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Setup variables
id: vars
shell: bash
run: |
DIR=$(echo "${{ needs.setup.outputs.appname }}-${{ needs.setup.outputs.tag }}")
echo "dir=$DIR" >> $GITHUB_OUTPUT
- name: Cache cargo registry
uses: actions/cache@v1
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Setup
run: rustup update stable
- name: Setup Rust (1/2) (toolchain)
uses: taiki-e/setup-cross-toolchain-action@v1
if: matrix.os == 'ubuntu-latest'
with:
target: ${{ matrix.target }}
- name: Cross build (macOS)
if: matrix.os == 'macos-latest'
run: |
rustup target add ${{ matrix.target }}
cargo build --release --target ${{ matrix.target }}
- name: Cross build (Linux and Windows)
run: |
cargo build --release --target ${{ matrix.target }}
# publish release
- name: Create release file
shell: bash
run: |
DIR=${{ steps.vars.outputs.dir }}
DIST=${{ matrix.target }}
mkdir -p dist/$DIST/$DIR
# cp -r site/public dist/$DIST/$DIR/docs
cp -r README.md LICENSE target/completions target/${{ matrix.target }}/release/${{ matrix.artifact_name }} dist/$DIST/$DIR
tar cvfz dist/${{ matrix.asset_name }}.tar.gz -C dist/$DIST $DIR
- name: Upload release assets
id: upload-release-assets
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
asset_path: dist/${{ matrix.asset_name }}.tar.gz
asset_name: ${{ matrix.asset_name }}.tar.gz
asset_content_type: application/x-gzip
upload_url: ${{ needs.setup.outputs.upload_url }}
docker:
needs: publish
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Docker buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Metadata
id: meta
uses: docker/metadata-action@v5
with:
# ${{ github.repository }} = tamada/totebag
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest
type=sha,prefix=,suffix=,format=short
type=raw,value=${{ needs.publish.outputs.tag }}
- name: Checkout the project
uses: actions/checkout@v4
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository}}:buildcache
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max