-
Notifications
You must be signed in to change notification settings - Fork 4
177 lines (152 loc) · 5.64 KB
/
publish-and-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
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
name: Publish crate and binaries
on:
workflow_dispatch:
jobs:
repo-prep:
name: Prepare versioning and changelogs for release
runs-on: ubuntu-latest
concurrency: publish-mutex
outputs: # TODO: See if these are still needed after refactoring
changelog-body: ${{ steps.generate-changelog.outputs.stdout }}
commit-hash: ${{ steps.commit.outputs.commit_hash }}
new-tag: ${{ steps.set-version.outputs.version_tag }}
version: ${{ steps.set-version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GH_ADMIN_COMMIT_TOKEN }}
- name: Get latest existing tag
uses: actions-ecosystem/action-get-latest-tag@v1
## NEEDS UPDATE for set-output deprecation.
## See https://github.com/actions-ecosystem/action-get-latest-tag/issues/25.
id: get-latest-tag
with:
semver_only: true
- name: Set new version
uses: paulhatch/[email protected]
## NEEDS UPDATE for set-output deprecation.
## See https://github.com/PaulHatch/semantic-version/issues/66.
id: set-version
with:
tag_prefix: "v"
format: "${major}.${minor}.${patch}"
major_pattern: "(MAJOR)"
minor_pattern: "(MINOR)"
- name: Generate changelog since last tag
uses: mathiasvr/command-output@v1
## NEEDS UPDATE for set-output deprecation.
## See https://github.com/mathiasvr/command-output/issues/4.
id: generate-changelog
with:
run: echo blah blah blah
- name: Log version & changelog
run: |
echo "Version: $VERSION"
echo "Version tag: $VERSION_TAG"
echo "Latest tag detected: $LATEST_TAG"
echo "Changelog: $CHANGELOG"
env:
VERSION: ${{ steps.set-version.outputs.version }}
VERSION_TAG: ${{ steps.set-version.outputs.version_tag }}
LATEST_TAG: ${{ steps.get-latest-tag.outputs.tag }}
CHANGELOG: ${{ steps.generate-changelog.outputs.stdout }}
- name: Prevent empty release
if: ${{ steps.generate-changelog.outputs.stdout == '' }}
uses: actions/github-script@v3
with:
script: |
core.setFailed("No changes since prior release")
- name: Update changelog
run: |
(head -8 CHANGELOG.md && echo "## $VERSION" && date "+_%d %B %Y_" && echo "" && (echo "$CHANGELOG" | sed -E 's_\(#([0-9]+)\)_([#\1](https://github.com/contentauth/c2pa-rs/pull/\1)\)_') && tail -n +9 CHANGELOG.md) > CHANGELOG.new.md
mv CHANGELOG.new.md CHANGELOG.md
env:
VERSION: ${{ steps.set-version.outputs.version }}
CHANGELOG: ${{ steps.generate-changelog.outputs.stdout }}
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Bump crate versions
run: |
sed -i "s/^version = \"[^\"]*\"$/version = \"$VERSION\"/;" Cargo.toml
env:
VERSION: ${{ steps.set-version.outputs.version }}
- name: Update Cargo.lock
run: |
cargo update -p c2pa-attacks
- name: Report differences for "prepare (release)" commit
run: git diff
- name: Commit Cargo.toml, Cargo.lock, and changelog
uses: stefanzweifel/git-auto-commit-action@v4
## NEEDS UPDATE for set-output deprecation.
## See https://github.com/stefanzweifel/git-auto-commit-action/issues/250.
id: commit
with:
commit_message: Prepare ${{ steps.set-version.outputs.version }} release
commit_user_name: Adobe CAI Team
commit_user_email: [email protected]
- name: Create GitHub release
uses: ncipollo/release-action@v1
with:
body: ${{ steps.generate-changelog.outputs.stdout }}
commit: ${{ steps.commit.outputs.commit_hash }}
prerelease: true # remove at 1.0
tag: ${{ steps.set-version.outputs.version_tag }}
token: ${{ secrets.GH_ADMIN_COMMIT_TOKEN }}
release-crate:
name: Release c2pa-attacks Rust crate
needs: repo-prep
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ needs.repo-prep.outputs.commit-hash }}
- name: Publish crate
run: |
cargo publish --token $CRATES_IO_SECRET
env:
CRATES_IO_SECRET: ${{ secrets.CRATES_IO_SECRET }}
publish-binaries:
name: Publish c2pa-attacks binaries
runs-on: ${{ matrix.os }}
needs: repo-prep
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
rust_version: [stable]
experimental: [false]
include:
- os: macos-latest
artifact_name: c2pa-attacks_mac_universal.zip
- os: ubuntu-latest
artifact_name: c2pa-attacks_linux_intel.tar.gz
- os: windows-latest
artifact_name: c2pa-attacks_win_intel.zip
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ needs.repo-prep.outputs.commit-hash }}
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust_version }}
components: llvm-tools-preview
override: true
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v1
- name: Run make release
run: make release
- name: Upload binary to github
uses: svenstaro/upload-release-action@v1-release
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/${{ matrix.artifact_name }}
asset_name: ${{ matrix.artifact_name }}
tag: ${{ needs.repo-prep.outputs.new-tag }}
overwrite: true