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
name: Release Please
on:
workflow_run:
workflows: # Name of the CI workflow file (rust.yml)
types:
- completed
branches:
- master
# Keep workflow_call if needed for other workflows to get release info
workflow_call:
outputs:
release_created:
description: "Whether a release was created by release-please"
value: ${{ jobs.release-please.outputs.created }}
permissions:
contents: write
pull-requests: write
issues: write
jobs:
release-please:
name: Run release-please
runs-on: ubuntu-latest
# Add condition to only run if the triggering workflow succeeded
if: ${{ github.event.workflow_run.conclusion == 'success' }}
outputs:
created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
upload_url: ${{ steps.release.outputs.upload_url }}
steps:
# Checkout the code from the commit that triggered the Rust CI workflow
- uses: actions/checkout@v4
with:
# Use the SHA from the workflow_run event
ref: ${{ github.event.workflow_run.head_sha }}
- uses: googleapis/release-please-action@v4
id: release
with:
release-type: rust
# Optionally configure package name if Cargo.toml is not at the root
# package-name: your-crate-name
# You might need a PAT instead of GITHUB_TOKEN if you hit permission issues
# token: ${{ secrets.YOUR_PAT }}
# build-and-upload-binaries:
# name: Build & Upload Binaries
# needs: release-please
# if: needs.release-please.outputs.created == 'true'
# runs-on: ${{ matrix.os }}
# permissions:
# contents: write # Needed to upload release assets
# strategy:
# matrix:
# include:
# - os: ubuntu-latest
# target: x86_64-unknown-linux-gnu
# asset_ext: tar.gz
# binary_ext: ""
# - os: macos-latest # Should default to x86_64 runner
# target: x86_64-apple-darwin
# asset_ext: tar.gz
# binary_ext: ""
# - os: macos-latest # M1/M2 Macs
# target: aarch64-apple-darwin
# asset_ext: tar.gz
# binary_ext: ""
# - os: windows-latest
# target: x86_64-pc-windows-msvc
# asset_ext: zip
# binary_ext: .exe
# steps:
# - name: Checkout code for the release tag
# uses: actions/checkout@v4
# with:
# ref: ${{ needs.release-please.outputs.tag_name }}
# - name: Set up Rust toolchain
# uses: dtolnay/rust-toolchain@stable
# with:
# target: ${{ matrix.target }}
# - name: Cache dependencies
# uses: Swatinem/rust-cache@v2
# - name: Build binary
# run: cargo build --release --target ${{ matrix.target }}
# - name: Prepare artifacts (Linux/macOS)
# if: matrix.os != 'windows-latest'
# run: |
# cd target/${{ matrix.target }}/release
# strip papersmith || true # Try stripping, ignore if fails
# tar czf ../../../papersmith-${{ needs.release-please.outputs.tag_name }}-${{ matrix.target }}.tar.gz papersmith
# cd ../../..
# shell: bash
# - name: Prepare artifacts (Windows)
# if: matrix.os == 'windows-latest'
# run: |
# cd target/${{ matrix.target }}/release
# # Use Compress-Archive from PowerShell standard library
# Compress-Archive -Path papersmith.exe -DestinationPath ../../../papersmith-${{ needs.release-please.outputs.tag_name }}-${{ matrix.target }}.zip
# cd ../../..
# shell: pwsh # Use PowerShell
# - name: Upload Release Asset
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ needs.release-please.outputs.upload_url }}
# asset_path: ./papersmith-${{ needs.release-please.outputs.tag_name }}-${{ matrix.target }}.${{ matrix.asset_ext }}
# asset_name: papersmith-${{ needs.release-please.outputs.tag_name }}-${{ matrix.target }}.${{ matrix.asset_ext }}
# asset_content_type: application/zip # Use application/zip consistently
# publish:
# name: Publish to crates.io
# needs: [release-please]
# runs-on: ubuntu-latest
# # This job also already checks if release-please created a release.
# if: needs.release-please.outputs.created == 'true'
# environment: # Optional: Use GitHub Environments for added security/control
# name: crates_io
# url: https://crates.io/crates/papersmith # Replace 'papersmith' if your crate name differs
# steps:
# - uses: actions/checkout@v4
# with:
# # Checkout the specific tag created by release-please
# ref: ${{ needs.release-please.outputs.tag_name }}
# - name: Set up Rust toolchain
# uses: dtolnay/rust-toolchain@stable
# - name: Cache cargo dependencies
# uses: Swatinem/rust-cache@v2
# - name: Publish crate
# run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
# env:
# CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}