forked from Pi4J/pi4j
-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (129 loc) · 5.08 KB
/
Copy pathci-main-snapshot.yml
File metadata and controls
150 lines (129 loc) · 5.08 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
name: "Build snapshot and deploy to Maven"
on:
push:
branches: [ "main" ]
workflow_dispatch:
jobs:
Build:
name: Build & Deploy Snapshot
runs-on: ubuntu-latest
if: github.repository == 'Pi4J/pi4j'
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get remove --purge man-db
sudo apt-get install --yes build-essential linux-headers-$(uname -r) sudo libi2c-dev linux-modules-extra-$(uname -r)
- name: Install JDK25
uses: sfesenko/setup-sdkman@v1
with:
deps: java:25-zulu
- name: Create Maven settings
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
run: |
mkdir -p ~/.m2
printf '<settings><servers><server><id>sonatype-oss-snapshots</id><username>%s</username><password>%s</password></server></servers></settings>' "$MAVEN_USERNAME" "$MAVEN_PASSWORD" > ~/.m2/settings.xml
- name: Create and add current user to suitable groups
run: |
sudo addgroup spi
sudo adduser $USER spi
sudo adduser $USER i2c
sudo adduser $USER dialout
- name: Add proper udev rules and trigger udevadm
run: |
sudo cp udev.rules /etc/udev/rules.d/99-pi4j-io.rules
sudo udevadm control --reload-rules && sudo udevadm trigger
- name: Cache local Maven repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Validate secrets are available
run: |
if [ -z "${{ secrets.OSSRH_USERNAME }}" ]; then
echo "ERROR: OSSRH_USERNAME secret is not set"
exit 1
fi
if [ -z "${{ secrets.OSSRH_TOKEN }}" ]; then
echo "ERROR: OSSRH_TOKEN secret is not set"
exit 1
fi
echo "✅ Both OSSRH_USERNAME and OSSRH_TOKEN secrets are available"
echo "Username length: ${#MAVEN_USERNAME}"
echo "Token length: ${#MAVEN_PASSWORD}"
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
- name: Verify Maven settings
run: |
echo "Generated Maven settings.xml:"
cat ~/.m2/settings.xml || echo "No settings.xml found"
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
- name: Build entire Pi4J Project
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
run: sudo -u $USER bash -c 'source ~/.sdkman/bin/sdkman-init.sh && ./mvnw deploy'
- name: Make staging directory
run: mkdir staging
- name: Build download archive
run: |
VERSION=$(grep -m1 '<version>' pom.xml | sed -E 's/.*<version>([^<]+)<\/version>.*/\1/')
mkdir -p bundle/core bundle/plugins bundle/test bundle/docs
cp -v LICENSE.txt NOTICE.txt README.md bundle/docs/
cp -v pi4j-core/target/pi4j-core-*.jar bundle/core/ || true
cp -v pi4j-test/target/pi4j-test-*.jar bundle/test/ || true
find plugins -type f -path '*/target/pi4j-*.jar' -exec cp -v {} bundle/plugins/ \;
(cd bundle && zip -r "../staging/pi4j-${VERSION}.zip" .)
ls -lh staging
- name: Upload distribution files to staging
uses: actions/upload-artifact@v4
with:
name: pi4j-dist
path: staging
DeployPackages:
name: Deploy to Download Repo
needs: [ Build ]
runs-on: ubuntu-latest
if: github.repository == 'Pi4J/pi4j'
concurrency:
group: deploy-to-download-repo
cancel-in-progress: false
environment:
name: Staging
url: 'https://github.com/Pi4J/download'
steps:
- name: Download staged artifacts from build
uses: actions/download-artifact@v4
with:
name: pi4j-dist
- name: Display downloaded build artifacts
shell: bash
run: tree
- name: Publish build archives to download repository
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
run: |
git clone --single-branch --branch main \
https://${API_TOKEN_GITHUB}@github.com/pi4j/download.git /tmp/download-repo
cp pi4j-*.zip /tmp/download-repo/
cd /tmp/download-repo
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git config user.name 'github-actions[bot]'
git add .
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
fi
git commit -m "Update from https://github.com/${{ github.repository }}/commit/${{ github.sha }}"
for i in 1 2 3; do
git push origin main && break
echo "Push attempt $i failed, rebasing and retrying..."
git pull --rebase origin main
done