-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
172 lines (152 loc) · 6.56 KB
/
action.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
---
name: semantic-release-rust-library
description: GitHub Action to semantically release your Rust library
author: EricCrosson
branding:
icon: package
color: orange
# Use a composite action for access to github.action_path
# (which is only supported in composite actions)
inputs:
toolchain:
description: Rust toolchain specification -- see https://rust-lang.github.io/rustup/concepts/toolchains.html#toolchain-specification
required: false
type: string
default: stable
test-command:
description: Command used to test your Rust program
required: false
type: string
default: cargo test
enable-semantic-release-git:
description: Use @semantic-release/git in your release flow. Only takes effect if the action semantic-release config is used.
type: boolean
default: true
cargo-registry-token:
description: API token for writing to your cargo registry
required: true
runs:
using: composite
steps:
- name: Checkout
uses: actions/checkout@v3
with:
# Fetch all history and tags for calculating next semantic version
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
id: rust-toolchain
with:
toolchain: ${{ inputs.toolchain }}
- name: Cache cargo
uses: actions/cache@v3
id: cache-cargo
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }}
- run: |
: test
${{ inputs.test-command }}
shell: bash
- name: Install is-semantic-release-configured
uses: EricCrosson/install-github-release-binary@v2
with:
targets: EricCrosson/is-semantic-release-configured@v1
# Terminology:
#
# - The "host" is the repository calling this action.
# - The "action" is this action.
#
# When we use the action's semantic-release configuration,
# install node_modules into an ephemeral .semantic-release-action_rust directory.
# Add this directory and the semantic-release manifest to the global gitignore.
#
# This has the following benefits:
#
# - @semantic-release/changelog does not try to commit the npm package manifest
# - cargo does not include git-ignored files in the package upload
- id: is-semantic-release-configured
run: |
: test for semantic-release configuration
if is-semantic-release-configured; then
echo "::debug::Detected semantic-release configuration, using host repository's configuration"
echo "host-configuration=true" >> "$GITHUB_OUTPUT"
echo "semantic_release=./node_modules/.bin/semantic-release" >> "$GITHUB_ENV"
else
echo "::debug::Did not detect semantic-release configuration, using this action's built-in configuration"
echo "host-configuration=false" >> "$GITHUB_OUTPUT"
echo "semantic_release=$GITHUB_WORKSPACE/.semantic-release-action_rust/semantic-release-library/node_modules/.bin/semantic-release" >> "$GITHUB_ENV"
echo "node_workdir=$GITHUB_WORKSPACE/.semantic-release-action_rust/semantic-release-library/" >> "$GITHUB_ENV"
mkdir -p "$GITHUB_WORKSPACE/.semantic-release-action_rust/semantic-release-library/"
fi
shell: bash
- if: steps.is-semantic-release-configured.outputs.host-configuration == 'false'
run: |
: configure Node.js path
echo NODE_PATH="$node_workdir${NODE_PATH:+":$NODE_PATH"}" >> "$GITHUB_ENV"
shell: bash
- if: steps.is-semantic-release-configured.outputs.host-configuration == 'false'
run: |
: configure git to ignore semantic-release manifest
mkdir -p "$HOME/.config/git"
echo "/.releaserc.json" >> "$HOME/.config/git/ignore"
echo "/.semantic-release-action_rust/" >> "$HOME/.config/git/ignore"
shell: bash
- if: steps.is-semantic-release-configured.outputs.host-configuration == 'false'
run: |
: install semantic-release manifest
cp "${{ github.action_path }}/package.json" "${{ env.node_workdir }}/package.json"
cp "${{ github.action_path }}/package-lock.json" "${{ env.node_workdir }}/package-lock.json"
cp "${{ github.action_path }}/.releaserc.json" ".releaserc.json"
shell: bash
- name: Install is-semantic-release-configured
if: steps.is-semantic-release-configured.outputs.host-configuration == 'false' && !inputs.enable-semantic-release-git
uses: EricCrosson/install-github-release-binary@v2
with:
targets: EricCrosson/configure-semantic-release-manifest@v1
- if: steps.is-semantic-release-configured.outputs.host-configuration == 'false' && !inputs.enable-semantic-release-git
run: |
: disable @semantic-release/git
configure-semantic-release-manifest --in-place --remove @semantic-release/git
shell: bash
- name: Configure Node.js
uses: actions/setup-node@v3
with:
node-version: lts/*
- name: Cache host npm dependencies
if: steps.is-semantic-release-configured.outputs.host-configuration == 'true'
uses: actions/cache@v3
id: cache-host-node-modules
with:
path: node_modules
key: ${{ runner.os }}-node-host-${{ hashFiles('package.json', 'package-lock.json') }}
- if: steps.is-semantic-release-configured.outputs.host-configuration == 'true' && steps.cache-host-node-modules.outputs.cache-hit != 'true'
run: |
: install host npm dependencies
npm ci --loglevel error
shell: bash
- name: Cache action npm dependencies
if: steps.is-semantic-release-configured.outputs.host-configuration == 'false'
uses: actions/cache@v3
id: cache-action-node-modules
with:
path: .semantic-release-action_rust/semantic-release-library/node_modules
key: ${{ runner.os }}-node-action-${{ hashFiles('.semantic-release-action_rust/semantic-release-library/package-lock.json') }}
- if: steps.is-semantic-release-configured.outputs.host-configuration == 'false' && steps.cache-action-node-modules.outputs.cache-hit != 'true'
run: |
: install action npm dependencies
npm ci --ignore-scripts --loglevel error
working-directory: ${{ env.node_workdir }}
shell: bash
- run: |
: invoke semantic-release
${semantic_release}
env:
GITHUB_TOKEN: ${{ github.token }}
CARGO_REGISTRY_TOKEN: ${{ inputs.cargo-registry-token }}
shell: bash