-
Notifications
You must be signed in to change notification settings - Fork 9
170 lines (163 loc) · 6.56 KB
/
Copy pathrelease-ci.yml
File metadata and controls
170 lines (163 loc) · 6.56 KB
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
# Create release workflow
name: 'Release-CI'
on:
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., 3.1.5)'
required: true
branches: [main]
# Avoid overlapping runs and cancel in-progress runs on newer commits
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Reduce default permissions for security
permissions:
contents: write
jobs:
# Shell script linting
shellcheck:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- name: Run ShellCheck
run: shellcheck -s sh server/*.sh
# Run tests
test:
runs-on: ubuntu-24.04
needs: [shellcheck]
defaults:
run:
working-directory: react
strategy:
matrix:
node-version: [24.x]
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: ./.github/actions/common-setup
with:
node-version: ${{ matrix.node-version }}
- name: Update version
run: npm version ${{ github.event.inputs.version }} --no-git-tag-version
- name: Run tests
run: npm run test:CI
# Build the project and create release asset
build:
runs-on: ubuntu-24.04
needs: [test]
strategy:
matrix:
node-version: [24.x]
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: ./.github/actions/common-setup
with:
node-version: ${{ matrix.node-version }}
- name: Update version
run: npm version ${{ github.event.inputs.version }} --no-git-tag-version
working-directory: react
- name: Build
run: npm run build
working-directory: react
- name: Create release asset
run: tar -cvzf bwmon.tar.gz react/build server
- name: Upload build artifacts
uses: actions/upload-artifact@v7
with:
name: build-artifacts
path: react/build
- name: Upload tarball artifact
uses: actions/upload-artifact@v7
with:
name: build-tarball
path: bwmon.tar.gz
# Create git tag, GitHub release, and update README
release:
runs-on: ubuntu-24.04
needs: [build]
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Download tarball artifact
uses: actions/download-artifact@v4
with:
name: build-tarball
path: .
- name: Ensure gh (GitHub CLI) is installed
run: |
if ! command -v gh >/dev/null 2>&1; then
echo "gh not found - installing"
sudo apt-get update && sudo apt-get install -y gh
else
gh --version
fi
- name: Setup git config
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Update version
run: npm version ${{ github.event.inputs.version }} --no-git-tag-version
working-directory: react
- name: Commit release
run: |
git status
git add -u
git commit -m "Version ${{ github.event.inputs.version }}" || echo "no changes to commit"
git push origin main --follow-tags || echo "push failed or blocked (branch protection?)"
git tag -a v${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}" || echo "tag already exists"
git push origin v${{ github.event.inputs.version }} || echo "tag push failed or tag already exists"
- name: Create or update release (idempotent)
run: |
set -e
TAG="v${{ github.event.inputs.version }}"
ASSET="bwmon.tar.gz"
if gh release view "$TAG" >/dev/null 2>&1; then
echo "Release $TAG already exists; uploading asset (clobber if present)"
gh release upload "$TAG" "$ASSET" --clobber
else
echo "Creating release $TAG"
gh release create "$TAG" "$ASSET" --title "Release $TAG" --generate-notes
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update README with new release version
run: |
sed -i "s|wget https://github.com/VREMSoftwareDevelopment/bwmon/releases/download/v[0-9.\-]*/bwmon.tar.gz|wget https://github.com/VREMSoftwareDevelopment/bwmon/releases/download/v${{ github.event.inputs.version }}/bwmon.tar.gz|g" README.md
sed -i "s|Try a demo version of this application|Try the latest demo version|g" README.md
shell: bash
- name: Commit updated README
run: |
git add README.md
git commit -m "Update README for release v${{ github.event.inputs.version }}" || echo "No README changes to commit"
git push origin main || echo "README push failed or blocked"
# Deploy the build to GitHub Pages
deploy:
runs-on: ubuntu-24.04
needs: [release]
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: gh-pages
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: .
- name: Deploy to GitHub Pages
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
touch .nojekyll
git add .nojekyll .
git commit -m "Deploy to GitHub Pages: ${{ github.sha }}" || echo "No changes to commit"
git status
git push origin gh-pages --force
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}