-
Notifications
You must be signed in to change notification settings - Fork 3
181 lines (154 loc) · 6.52 KB
/
release.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
173
174
175
176
177
178
179
180
181
# Test openMINDS MATLAB Toolbox across all supported releases of MATLAB, package toolbox, create release
# Adapted from: https://github.com/mathworks/climatedatastore/blob/main/.github/workflows/release.yml
name: Create new release
# Run workflow when a tag is created
on:
push:
tags:
- 'v*'
jobs:
# This workflow contains:
# 1. a matrixed test job run across a bunch of releases of MATLAB
# 2. a reporting job that summarizes the tests, and updates release badge
test:
strategy:
fail-fast: false
matrix:
MATLABVersion: [R2022b, R2023a, R2023b, R2024a, R2024b]
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
# Checks-out the repository under $GITHUB_WORKSPACE, so the job can access it
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v2
with:
release: ${{ matrix.MATLABVersion }}
# Runs all tests in the project. Put results in a version specific subdirectory
- name: Run tests
uses: matlab-actions/run-command@v2
with:
command: |
addpath(genpath("tools"));
testToolbox('ReportSubdirectory',"${{ matrix.MATLABVersion }}", 'CreateBadge', false)
# Upload code coverage information to Codecov
- name: Upload code coverage report to Codecov (https://app.codecov.io/gh/openMetadataInitiative/openMINDS_MATLAB)
uses: codecov/codecov-action@v4
if: always()
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: docs/reports/codecoverage.xml
env_vars: ${{ matrix.MATLABVersion }}
# Save the contents of the report directory from each release into an artifact.
- name: Save report directory
uses: actions/upload-artifact@v4
if: always()
with:
name: reports-${{ matrix.MATLABVersion }}
path: docs/reports
# Report on what releases tested successfully.
# Generate a draft release based on the tag
# Recreate the tag with the final version of JSON files
release:
needs: test
if: always()
runs-on: ubuntu-latest
steps:
# Use deploy key to push back to protected branch
- name: Checkout repository using deploy key
uses: actions/checkout@v4
with:
ref: refs/heads/main
ssh-key: ${{ secrets.DEPLOY_KEY }}
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v2
# Copy all the reports down into the container
- uses: actions/download-artifact@v4
with:
pattern: reports-*
path: docs/reports
merge-multiple: true
# Generate the JSON for the releases tested badge
- name: Generate tested with badge
uses: matlab-actions/run-command@v2
with:
command: addpath(genpath("tools")), createTestedWithBadgeforToolbox("${{ github.ref_name }}")
# Publish test results from all the releases
- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
junit_files: "docs/reports/*/test-results.xml"
# Package the MLTBX
- name: Package toolbox
uses: matlab-actions/run-command@v2
with:
command: addpath(genpath("tools")), packageToolbox("specific","${{ github.ref_name }}")
# Define the versionNumber using underscores, as this is used in the MLTBX
- name: Set version number
id: set_version
run: |
versionNumber=$(echo "${{ github.ref_name }}" | sed 's/\./_/g')
echo "versionNumber=$versionNumber" >> $GITHUB_ENV
# Save the MLTBX.
- name: Save packaged toolbox
uses: actions/upload-artifact@v4
with:
name: openMINDS_MATLAB_${{ env.versionNumber }}.mltbx
path: releases/openMINDS_MATLAB_${{ env.versionNumber }}.mltbx
# Commit the updated Contents.m
- name: Commit updated Contents.m file
continue-on-error: true
run: |
git config user.name "${{ github.workflow }} by ${{ github.actor }}"
git config user.email "<>"
git status
git add code/Contents.m
git commit -m "Final checkins for release ${{ github.ref_name }}"
git fetch
git push
# Commit the JSON for the MATLAB releases test badge to gh-badges branch
- name: Checkout gh-badges branch
uses: actions/checkout@v4
with:
ref: gh-badges
path: gh-badges
token: ${{ secrets.GITHUB_TOKEN }}
- name: Push to gh-badges
run: |
mkdir -p gh-badges/.github/badges/${{ github.ref_name }}
cp .github/badges/${{ github.ref_name }}/tested_with.json gh-badges/.github/badges/${{ github.ref_name }}/tested_with.json
cd gh-badges
git config user.name "${{ github.workflow }} by ${{ github.actor }}"
git config user.email "<>"
# Only proceed with commit and push if changes are detected
if [[ $(git add .github/badges/* --dry-run | wc -l) -gt 0 ]]; then
git add .github/badges/*
git commit -m "Update tested with badge for release"
git push -f
else
echo "Nothing to commit"
fi
# Retag the repo so that the updated files are included in the release tag
- name: Update tag
if: always()
continue-on-error: true
run: |
git config user.name "${{ github.workflow }} by ${{ github.actor }}"
git config user.email "<>"
# Delete the existing tag locally and remotely
git tag -d "${{ github.ref_name }}"
git push origin --delete "${{ github.ref_name }}"
# Recreate the tag with a message, including [skip ci] to prevent CI workflows
git tag -a "${{ github.ref_name }}" -m "Release ${{ github.ref_name }} [skip ci]"
# Push the new tag to the remote repository
git push origin "${{ github.ref_name }}"
# Create the release
- name: Create GitHub release
uses: ncipollo/release-action@v1
with:
draft: true
artifacts: "releases/openMINDS_MATLAB_${{ env.versionNumber }}.mltbx"
generateReleaseNotes: true
body: "![MATLAB Versions Tested](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FopenMetadataInitiative%2FopenMINDS_MATLAB%2Fgh-badges%2F.github%2Fbadges%2F${{ github.ref_name }}%2Ftested_with.json)"