-
-
Notifications
You must be signed in to change notification settings - Fork 8
108 lines (94 loc) · 3.48 KB
/
publish.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
name: Publish
on:
pull_request_target:
branches: [main, master]
workflow_dispatch:
inputs:
sdk:
description: "Version of Playdate SDK, needed to validate crates."
default: latest
type: string
required: true
dry-run:
description: "Enable dry-run mode, actually skip execution `cargo publish`."
default: false
type: boolean
required: false
check-repo:
description: "Check repository consistency."
default: true
type: boolean
required: false
push:
branches: [main, master]
schedule:
- cron: "0 0 * * 1"
env:
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
CARGO_TERM_COLOR: always
CARGO_TERM_PROGRESS_WHEN: never
jobs:
crates-io:
name: crates.io
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- name: Install Deps
uses: ./.github/actions/tools-deps
- name: Install Playdate SDK
id: sdk
uses: pd-rs/get-playdate-sdk@main
with:
version: ${{ github.event.inputs.sdk || 'latest' }}
- name: SDK ${{ steps.sdk.outputs.version }} installed
run: which pdc && pdc --version
- name: Publish
id: publisher
uses: katyo/publish-crates@v2
with:
# From docs: `github.head_ref` is only available when the event that triggers
# a workflow run is either `pull_request` or `pull_request_target`.
dry-run: ${{ github.event.inputs.dry-run == 'true' || (github.head_ref && 'true') || 'false' }}
check-repo: ${{ (github.event.inputs && github.event.inputs.check-repo == 'true') || true }}
ignore-unpublished-changes: ${{ github.head_ref == 'false' }}
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Count published
id: counter
if: (github.event.inputs.dry-run == 'true' || (github.head_ref && 'true') || 'false') == 'false'
env:
CRATES: ${{ steps.publisher.outputs.published }}
run: |
echo "$CRATES"
CRATES_NUM=$(echo $CRATES | jq '. | length')
echo "value=$CRATES_NUM" >> "$GITHUB_OUTPUT"
LIST="${{ join(fromJSON(steps.publisher.outputs.published).*.name, ', ') }}"
echo "Published $CRATES_NUM crates: $LIST"
- name: Message
id: message
if: success()
env:
CRATES: ${{ steps.publisher.outputs.published }}
run: |
MESSAGE=$(echo $CRATES | jq -r 'if length == 1 then "Crate updated: \(.[0].name) v\(.[0].version)" else ("Crates updated:"), (to_entries[] | "\(.key + 1). \(.value.name): v\(.value.version)") end')
echo "$MESSAGE"
# Replace \n->\n is really nessessary! This encodes string to json string.
MESSAGE="\"${MESSAGE//$'\n'/'\n'}\""
echo "encoded: $MESSAGE"
echo "value<<EOF" >> $GITHUB_OUTPUT
echo $MESSAGE >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
outputs:
published: ${{ steps.publisher.outputs.published }}
counter: ${{ steps.counter.outputs.value }}
message: ${{ steps.message.outputs.value }}
post:
needs: crates-io
if: join(fromJSON(needs.crates-io.outputs.published).*.name, '-') && (github.event.inputs.dry-run == 'true' || (github.head_ref && 'true') || 'false') == 'false'
uses: ./.github/workflows/post.yml
secrets: inherit
with:
message: ${{ needs.crates-io.outputs.message }}