55 - main
66 tags :
77 - v*
8- pull_request :
8+ pull_request : { }
99 workflow_dispatch :
10+ inputs :
11+ hex_repo :
12+ description : " hex repo to publish to"
13+ default : staging
14+ required : true
15+ options :
16+ - staging
17+ - prod
18+
1019 schedule :
1120 # Nightly run; execute daily at 07:37 AM UTC on main (default branch). This is an hour
1221 # after the Rust checks.
2029 # cached state
2130 cache_key : init
2231
32+ package_artifact : ts_elixir-${{ github.sha }}
33+
34+ is_tag_push : ${{ startsWith(github.ref, 'refs/tags/') }}
35+ is_dispatch : ${{ github.event_name == 'workflow_dispatch' }}
36+
37+ hex_environment : &hex_environment ${{ case(inputs.hex_repo == 'prod', 'hex.pm', 'staging.hex.pm') }}
38+
39+ latest_elixir : &latest_elixir 1.19.5
40+ latest_otp : &latest_otp 28.4.2
41+ latest_rust : &latest_rust 1.94.0
42+
43+ defaults :
44+ run :
45+ working-directory : ts_elixir
46+
2347jobs :
2448 build_test :
2549 name : compile, test, static checks (elixir ${{ matrix.elixir.label }}, otp ${{ matrix.otp.label }}, rust ${{ matrix.rust_toolchain.label }})
@@ -28,19 +52,15 @@ jobs:
2852 strategy :
2953 matrix :
3054 elixir :
31- - version : 1.19.5
55+ - version : *latest_elixir
3256 label : latest
3357 otp :
34- - version : 28.4.2
58+ - version : *latest_otp
3559 label : latest
3660 rust_toolchain :
37- - version : 1.94.0
61+ - version : *latest_rust
3862 label : latest
3963
40- defaults :
41- run :
42- working-directory : ts_elixir
43-
4464 steps :
4565 - name : Checkout
4666 uses : actions/checkout@v6
@@ -120,3 +140,115 @@ jobs:
120140 name : exdoc-${{ github.sha }}
121141 path : ts_elixir/doc
122142 retention-days : 7
143+
144+ - &detach_cargo_toml
145+ name : Detach Cargo.toml from workspace
146+ working-directory : ts_elixir/native/ts_elixir
147+ run : |
148+ pip install tomli-w
149+
150+ python deworkspace_cargo_toml.py \
151+ --root ../../../Cargo.toml \
152+ --repo_sha ${{ github.sha }} \
153+ < Cargo.toml > Cargo.toml.new
154+
155+ mv Cargo.toml.new Cargo.toml
156+ echo generated Cargo.toml:
157+ cat Cargo.toml
158+
159+ - name : Build Hex package (no publish)
160+ run : mix hex.build --unpack -o tailscale
161+ env :
162+ MIX_ENV : prod
163+
164+ - name : Upload package tarball
165+ uses : actions/upload-artifact@v7
166+ with :
167+ name : ${{ env.package_artifact }}
168+ path : ts_elixir/tailscale
169+
170+ publish :
171+ name : publish
172+ runs-on : linux-x86_64-16cpu
173+ needs : build_test
174+ # if: ${{ startsWith(github.ref, 'refs/tags/*') || github.event_name == 'workflow_dispatch' }}
175+
176+ environment : *hex_environment
177+
178+ # Artifact generation, signing, upload, respectively
179+ permissions :
180+ attestations : write
181+ id-token : write
182+ contents : write
183+
184+ steps :
185+ - name : Checkout
186+ uses : actions/checkout@v6
187+
188+ - name : Cache mix
189+ id : cache-mix
190+ uses : actions/cache@v5
191+ with :
192+ path : |
193+ ~/.mix
194+ ts_elixir/_build/
195+ ts_elixir/deps/
196+ key : ${{ runner.os }}-mix-${{ env.cache_key }}-elixir-${{ env.latest_elixir }}-otp-${{ env.latest_otp }}-${{ hashFiles('**/mix.lock') }}
197+
198+ - name : Cache Rust
199+ id : cache-rust-elixir
200+ uses : actions/cache@v5
201+ with :
202+ path : |
203+ ~/.cargo/bin/
204+ ~/.cargo/registry/index/
205+ ~/.cargo/registry/cache/
206+ ~/.cargo/git/db/
207+ ~/.rustup/toolchains
208+ target/
209+ key : ${{ runner.os }}-elixir-rs-${{ env.cache_key }}-${{ env.latest_rust }}-${{ hashFiles('**/Cargo.lock') }}
210+
211+ - name : Install elixir
212+ id : install-elixir
213+ uses : erlef/setup-beam@v1.24.0
214+ with :
215+ otp-version : ${{ env.latest_otp }}
216+ elixir-version : ${{ env.latest_elixir }}
217+
218+ - name : Install Rust toolchain
219+ id : install-rust-toolchain
220+ if : steps.cache-rust-elixir.outputs.cache-hit != 'true'
221+ uses : dtolnay/rust-toolchain@master
222+ with :
223+ toolchain : ${{ env.latest_rust }}
224+
225+ - name : Install dependencies
226+ run : mix deps.get
227+
228+ - name : Compile dependencies
229+ run : mix deps.compile
230+
231+ - name : Download built package
232+ uses : actions/download-artifact@v8
233+ with :
234+ name : ${{ env.package_artifact }}
235+ path : ts_elixir/tailscale
236+
237+ - name : Generate attestation
238+ uses : actions/attest@v4
239+ with :
240+ subject-path : ts_elixir/tailscale
241+
242+ - *detach_cargo_toml
243+
244+ - name : Publish (dry run)
245+ run : mix hex.publish --dry-run --yes
246+ env :
247+ HEX_API_URL : ${{ vars.HEX_API_URL }}
248+ HEX_API_KEY : ${{ secrets.HEX_API_KEY }}
249+
250+ - name : Publish
251+ run : mix hex.publish --yes
252+ env :
253+ HEX_API_KEY : ${{ secrets.HEX_API_KEY }}
254+ HEX_API_URL : ${{ vars.HEX_API_URL }}
0 commit comments