-
Notifications
You must be signed in to change notification settings - Fork 2
160 lines (159 loc) · 5.23 KB
/
test-and-deploy.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
name: test-and-deploy
on:
push:
branches-ignore:
- renovate/**
pull_request:
jobs:
tests:
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
os:
- ubuntu-24.04
# - windows
- macos-14
runs-on: ${{ matrix.os }}
concurrency:
group: ${{ github.workflow }}-test-${{ matrix.os }}-${{ github.event.number || github.ref }}
steps:
- name: Setup Java
uses: actions/[email protected]
with:
distribution: temurin
java-version: 21
- name: Setup WSL
if: runner.os == 'Windows'
uses: Vampire/[email protected]
with:
distribution: Ubuntu-22.04
- name: Configure WSL
if: runner.os == 'Windows'
shell: wsl-bash {0}
run: |
sudo apt-get update
sudo apt-get install -y openjdk-21-jre-headless
- name: Checkout
uses: actions/[email protected]
- name: Tests
run: ./tests.main.kts
prepare-deliveries:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.deliveries.outputs.matrix }}
steps:
- name: Setup Java
uses: actions/[email protected]
with:
distribution: temurin
java-version: 21
- name: Compute ref
id: ref
run: |
ruby -e '\
if "${{ github.event_name }}" == "push" && "${{ github.event.ref }}".end_with?("/master") then
puts "::set-output name=ref::${{ github.event.after }}"
else
puts "::set-output name=ref::master"
end
'
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
ref: ${{ steps.ref.outputs.ref }}
submodules: recursive
- name: Prepare deliverable packages
id: deliveries
run: ./deployer.main.kts
- name: Tar files
run: tar -cvf build.tar build
- name: Upload artifact
uses: actions/[email protected]
with:
name: build
path: build.tar
delivery:
needs:
- tests # Don't deliver if testing fails
- prepare-deliveries
runs-on: ubuntu-latest
if: >-
!github.event.repository.fork
&& (
github.event_name != 'pull_request'
|| github.event.pull_request.head.repo.full_name == github.repository
)
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.prepare-deliveries.outputs.matrix) }}
max-parallel: 1
concurrency:
group: ${{ github.workflow }}-delivery-${{ matrix.type }}-${{ matrix.ref }}-${{ matrix.target }}-${{ matrix.owner }}-${{ matrix.repo }}-${{ github.event.number || github.ref }}
cancel-in-progress: false
steps:
- name: Checkout the local repo
if: matrix.type == 'repo'
uses: actions/[email protected]
- name: Checkout the target repo if it exists, initialize if needed
if: matrix.type == 'repo'
run: |
git clone https://${{ secrets.DEPLOYMENT_TOKEN }}@github.com/${{ matrix.owner }}/${{ matrix.repo }} target
cd target
git checkout ${{ matrix.ref }} || git checkout ${{ matrix.ref }} origin/${{ matrix.ref }} || git checkout -b ${{ matrix.ref }}
if ! git rev-parse HEAD &> /dev/null; then
echo 'The repository is empty, creating the target branch and adding a first commit'
git config user.name 'pianinator[bot]'
git config user.email '[email protected]'
git commit --allow-empty -m 'initialize the repository'
fi
- name: Check if the branch can release
id: can-release
run: |
echo "can-release=${{endsWith(github.ref, '/master') || endsWith(github.ref, '/exercises')}}" >> $GITHUB_OUTPUT
- name: Push the repo
if: matrix.type == 'repo' && steps.can-release.outputs.can-release == 'true'
working-directory: target
run: |
git push -u origin ${{ matrix.ref }}
- name: Download artifact
uses: actions/[email protected]
with:
name: build
- name: Unpack
run: tar -xf build.tar
- name: Deliver an archive
if: matrix.type == 'release' && steps.can-release.outputs.can-release == 'true'
uses: ncipollo/[email protected]
with:
allowUpdates: true
artifacts: ${{ matrix.target }}
owner: ${{ matrix.owner }}
repo: ${{ matrix.repo }}
replacesArtifacts: true
tag: ${{ matrix.ref }}
token: ${{ secrets.DEPLOYMENT_TOKEN }}
- name: Deliver a branch
if: matrix.type == 'repo' && steps.can-release.outputs.can-release == 'true'
uses: JamesIves/[email protected]
with:
folder: ${{ matrix.target }}
token: ${{ secrets.DEPLOYMENT_TOKEN }}
branch: ${{ matrix.ref }}
repository-name: ${{ matrix.owner }}/${{ matrix.repo }}
success:
runs-on: ubuntu-24.04
needs:
- delivery
- tests
if: >-
always() && (
contains(join(needs.*.result, ','), 'failure')
|| !contains(join(needs.*.result, ','), 'cancelled')
)
steps:
- name: Verify that there were no failures
run: ${{ !contains(join(needs.*.result, ','), 'failure') }}