forked from amazon-ion/ion-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (149 loc) · 7.24 KB
/
rust.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
name: CI Build
on: [push, pull_request]
jobs:
setup:
# This job sets up the runners to be used in the matrix for the build workflow.
# It provides a list of available runners with stable, human-friendly names and a mapping
# from those names to the actual `runs-on` value for each runner type. This allows us to
# use codebuild-hosted runners for amazon-ion/ion-rust without requiring forks to also
# have codebuild-hosted runners.
#
# If you want to use codebuild runners for your personal fork, follow the instructions to set
# up a codebuild project. https://docs.aws.amazon.com/codebuild/latest/userguide/action-runner.html
# Then, create a repository variable for your fork named `CODEBUILD_PROJECT_NAME` with the name
# of the project you created.
#
# TODO: See if this job can be turned into a reusable component
name: Setup Build Matrix
runs-on: ubuntu-latest
strategy:
matrix:
# We're using a matrix with a single entry so that we can define some config as YAML rather than
# having to write escaped json in a string.
include:
# Repository vars are not available for fork->source pull requests, so if we want to use codebuild runners
# for PRs, we need a fallback to check the repository owner.
- use-codebuild: ${{ vars.CODEBUILD_PROJECT_NAME != '' || github.repository_owner == 'amazon-ion' }}
codebuild-project-name: ${{ vars.CODEBUILD_PROJECT_NAME != '' && vars.CODEBUILD_PROJECT_NAME || 'ion-rust' }}
runs-on-names-cb: [ windows, macos, ubuntu, al2-intel, al2-arm ]
runs-on-names: [ windows, macos, ubuntu ]
al2-intel: "codebuild-${{ vars.CODEBUILD_PROJECT_NAME != '' && vars.CODEBUILD_PROJECT_NAME || 'ion-rust' }}-${{ github.run_id }}-${{ github.run_attempt }}-al2-5.0-large"
al2-arm: "codebuild-${{ vars.CODEBUILD_PROJECT_NAME != '' && vars.CODEBUILD_PROJECT_NAME || 'ion-rust' }}-${{ github.run_id }}-${{ github.run_attempt }}-arm-3.0-large"
outputs:
available-runners: ${{ matrix.use-codebuild && toJSON(matrix.runs-on-names-cb) || toJSON(matrix.runs-on-names) }}
runner-labels: ${{ env.runner-labels }}
windows: windows-latest
macos: macos-latest
ubuntu: ubuntu-latest
al2-intel: ${{ matrix.al2-intel }}
al2-arm: ${{ matrix.al2-arm }}
env:
codebuild-project-name: ${{ vars.CODEBUILD_PROJECT_NAME != '' && vars.CODEBUILD_PROJECT_NAME || 'ion-rust' }}
runner-labels: |
{
"windows": "windows-latest"
"macos": "macos-latest"
"ubuntu": "ubuntu-latest
"al2-intel": "${{ matrix.al2-intel }}"
"al2-arm": "${{ matrix.al2-arm }}"
}
steps:
- name: Dump Config
run: |
echo '${{ toJSON(matrix) }}'
echo '${{ env.runner-labels}}'
- id: set-matrix
run: echo "runner-labels={\"include\":[{\"project\":\"foo\",\"config\":\"Debug\"},{\"project\":\"bar\",\"config\":\"Release\"}]}" >> $GITHUB_OUTPUT
build:
name: Build and Test
needs: setup
strategy:
matrix:
# use the available runner types that were determined by the setup step
os: ${{ fromJSON(needs.setup.outputs.available-runners) }}
# build and test for different and interesting crate features
features: [ 'default', 'all', 'experimental-ion-hash', 'experimental' ]
# Map the friendly names from `available-runners` to the actual runner labels.
runs-on: ${{ needs.setup.outputs[matrix.os] }}
# We want to run on external PRs, but not on internal ones as push automatically builds
# H/T: https://github.com/Dart-Code/Dart-Code/commit/612732d5879730608baa9622bf7f5e5b7b51ae65
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'amazon-ion/ion-rust'
permissions:
checks: write
steps:
- name: Install Dependencies
if: runner.os == 'Windows'
run: choco install llvm -y
- name: Git Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Rust Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt, clippy
override: true
- name: Cargo Test (default/no features)
if: matrix.features == 'default'
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose --workspace
- name: Cargo Test (all features)
if: matrix.features == 'all'
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose --workspace --all-features
- name: Cargo Test (specific feature)
if: matrix.features != 'default' && matrix.features != 'all'
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose --workspace --features "${{ matrix.features }}"
- name: Rustfmt Check
# We really only need to run this once--ubuntu/all features mode is as good as any
if: matrix.os == 'ubuntu-latest' && matrix.features == 'all'
uses: actions-rs/cargo@v1
with:
command: fmt
args: --verbose -- --check
# `clippy-check` will run `cargo clippy` on new pull requests. Due to a limitation in GitHub
# permissions, the behavior of the Action is different depending on the source of the PR. If the
# PR comes from the ion-rust project itself, any suggestions will be added to the PR as comments.
# If the PR comes from a fork, any suggestions will be added to the Action's STDOUT for review.
# For details, see: https://github.com/actions-rs/clippy-check/issues/2
- name: Install Clippy
# The clippy check depends on setup steps defined above, but we don't want it to run
# for every OS because it posts its comments to the PR. These `if` checks limit clippy to
# only running on the Linux test. (The choice of OS was arbitrary.)
if: matrix.os == 'ubuntu' && matrix.features == 'all'
run: rustup component add clippy
- name: Run Clippy
if: matrix.os == 'ubuntu' && matrix.features == 'all'
uses: actions-rs/clippy-check@v1
with:
# Adding comments to the PR requires the GITHUB_TOKEN secret.
token: ${{ secrets.GITHUB_TOKEN }}
# We are opinionated here and fail the build if anything is complained about.
# We can always explicitly allow clippy things we disagree with or if this gets too annoying, get rid of it.
args: --workspace --all-features --tests -- -Dwarnings
- name: Rustdoc on Everything
# We really only need to run this once--ubuntu/all features mode is as good as any
if: matrix.os == 'ubuntu' && matrix.features == 'all'
uses: actions-rs/cargo@v1
with:
command: doc
args: --document-private-items --all-features
confirm-build:
# This job is just a "join" on all parallel strategies for the `build` job so that we can require it in our branch protection rules.
needs: build
name: Build and Test Confirmation
runs-on: ubuntu-latest
if: always()
steps:
- run: echo ${{ needs.build.outputs.result }}
- if: needs.build.outputs.result != 'success'
run: exit 1