|
4 | 4 | push: |
5 | 5 | branches: [main] |
6 | 6 |
|
7 | | -permissions: |
8 | | - contents: write |
9 | | - |
10 | | -env: |
11 | | - APT_DISTRO: ${{ vars.APT_DISTRO || 'trixie' }} |
12 | | - APT_COMPONENT: ${{ vars.APT_COMPONENT || 'hatlabs' }} |
13 | | - |
14 | 7 | jobs: |
15 | | - test: |
16 | | - runs-on: ubuntu-latest |
17 | | - steps: |
18 | | - - name: Checkout code |
19 | | - uses: actions/checkout@v6 |
20 | | - |
21 | | - - name: Run tests |
22 | | - uses: ./.github/actions/run-tests |
23 | | - |
24 | | - build-and-release: |
25 | | - needs: test |
26 | | - runs-on: ubuntu-latest-arm64 |
27 | | - steps: |
28 | | - - name: Checkout code |
29 | | - uses: actions/checkout@v6 |
30 | | - with: |
31 | | - fetch-depth: 0 |
32 | | - |
33 | | - - name: Read version from VERSION |
34 | | - id: version |
35 | | - run: .github/scripts/read-version.sh |
36 | | - |
37 | | - - name: Check if published release exists |
38 | | - id: check |
39 | | - run: .github/scripts/check-release-exists.sh "${{ steps.version.outputs.version }}" prerelease |
40 | | - env: |
41 | | - GH_TOKEN: ${{ github.token }} |
42 | | - |
43 | | - - name: Build .deb package |
44 | | - if: steps.check.outputs.action == 'create' |
45 | | - uses: ./.github/actions/build-deb |
46 | | - |
47 | | - - name: Rename package with distro+component suffix |
48 | | - if: steps.check.outputs.action == 'create' |
49 | | - run: | |
50 | | - VERSION="${{ steps.version.outputs.version }}" |
51 | | - OLD_NAME="halpi2-daemon_${VERSION}_arm64.deb" |
52 | | - NEW_NAME="halpi2-daemon_${VERSION}_arm64+${APT_DISTRO}+${APT_COMPONENT}.deb" |
53 | | -
|
54 | | - if [ -f "$OLD_NAME" ]; then |
55 | | - echo "📦 Renaming package: $(basename $OLD_NAME) → $(basename $NEW_NAME)" |
56 | | - mv "$OLD_NAME" "$NEW_NAME" |
57 | | - echo "✅ Package renamed successfully" |
58 | | - echo "Package location: $NEW_NAME" |
59 | | - else |
60 | | - echo "❌ Error: Expected package not found: $OLD_NAME" |
61 | | - exit 1 |
62 | | - fi |
63 | | -
|
64 | | - - name: Generate release notes |
65 | | - if: steps.check.outputs.action == 'create' |
66 | | - id: notes |
67 | | - run: .github/scripts/generate-release-notes.sh "${{ steps.version.outputs.version }}" "${{ steps.version.outputs.tag_version }}" prerelease |
68 | | - env: |
69 | | - GH_TOKEN: ${{ github.token }} |
70 | | - |
71 | | - - name: Delete existing pre-release |
72 | | - if: steps.check.outputs.action == 'create' |
73 | | - run: | |
74 | | - TAG_VERSION="${{ steps.version.outputs.tag_version }}" |
75 | | - if gh release view "v${TAG_VERSION}" &>/dev/null; then |
76 | | - IS_PRERELEASE=$(gh release view "v${TAG_VERSION}" --json isPrerelease --jq '.isPrerelease') |
77 | | - if [ "$IS_PRERELEASE" = "true" ]; then |
78 | | - echo "🗑️ Deleting existing pre-release v${TAG_VERSION}" |
79 | | - gh release delete "v${TAG_VERSION}" --yes --cleanup-tag |
80 | | - fi |
81 | | - fi |
82 | | - env: |
83 | | - GH_TOKEN: ${{ github.token }} |
84 | | - |
85 | | - - name: Create pre-release |
86 | | - if: steps.check.outputs.action == 'create' |
87 | | - run: | |
88 | | - TAG_VERSION="${{ steps.version.outputs.tag_version }}" |
89 | | - if ! ls *.deb 1> /dev/null 2>&1; then |
90 | | - echo "❌ Error: No .deb files found" |
91 | | - exit 1 |
92 | | - fi |
93 | | - echo "📦 Creating pre-release v${TAG_VERSION}" |
94 | | - gh release create "v${TAG_VERSION}" \ |
95 | | - --prerelease \ |
96 | | - --title "v${TAG_VERSION} (Pre-release)" \ |
97 | | - --notes-file release_notes.md \ |
98 | | - *.deb |
99 | | - echo "✅ Pre-release created successfully" |
100 | | - env: |
101 | | - GH_TOKEN: ${{ github.token }} |
102 | | - |
103 | | - - name: Create draft release |
104 | | - if: steps.check.outputs.action == 'create' |
105 | | - run: | |
106 | | - VERSION="${{ steps.version.outputs.version }}" |
107 | | - TAG_VERSION="${{ steps.version.outputs.tag_version }}" |
108 | | -
|
109 | | - # Check if draft release already exists |
110 | | - if gh release view "v${VERSION}" &>/dev/null; then |
111 | | - IS_DRAFT=$(gh release view "v${VERSION}" --json isDraft --jq '.isDraft') |
112 | | - IS_PRERELEASE=$(gh release view "v${VERSION}" --json isPrerelease --jq '.isPrerelease') |
113 | | -
|
114 | | - if [ "$IS_DRAFT" = "true" ] && [ "$IS_PRERELEASE" = "false" ]; then |
115 | | - echo "Draft release v${VERSION} already exists, skipping creation" |
116 | | - fi |
117 | | - else |
118 | | - # Generate release notes for draft |
119 | | - .github/scripts/generate-release-notes.sh "${VERSION}" "${VERSION}" draft |
120 | | -
|
121 | | - echo "📋 Creating draft release v${VERSION} with .deb package" |
122 | | - gh release create "v${VERSION}" \ |
123 | | - --draft \ |
124 | | - --title "v${VERSION}" \ |
125 | | - --notes-file release_notes.md \ |
126 | | - *.deb |
127 | | - echo "✅ Draft release created successfully with .deb attached" |
128 | | - fi |
129 | | - env: |
130 | | - GH_TOKEN: ${{ github.token }} |
131 | | - |
132 | | - - name: Dispatch to APT repository |
133 | | - if: steps.check.outputs.action == 'create' |
134 | | - uses: peter-evans/repository-dispatch@v4 |
135 | | - with: |
136 | | - token: ${{ secrets.REPO_DISPATCH_PAT }} |
137 | | - repository: hatlabs/apt.hatlabs.fi |
138 | | - event-type: package-updated |
139 | | - client-payload: | |
140 | | - { |
141 | | - "repository": "${{ github.repository }}", |
142 | | - "distro": "${{ env.APT_DISTRO }}", |
143 | | - "channel": "unstable", |
144 | | - "component": "${{ env.APT_COMPONENT }}" |
145 | | - } |
146 | | -
|
147 | | - - name: Report success |
148 | | - if: steps.check.outputs.action == 'create' |
149 | | - run: | |
150 | | - VERSION="${{ steps.version.outputs.version }}" |
151 | | - TAG_VERSION="${{ steps.version.outputs.tag_version }}" |
152 | | - echo "=== Main Branch CI/CD Complete ===" |
153 | | - echo "Package version: ${VERSION}" |
154 | | - echo "Release tag: v${TAG_VERSION}" |
155 | | - echo "Release URL: https://github.com/${{ github.repository }}/releases/tag/v${TAG_VERSION}" |
156 | | - echo "" |
157 | | - echo "✅ Pre-release created with .deb package" |
158 | | - echo "✅ Draft release created with .deb attached" |
159 | | - echo "✅ Dispatched to apt.hatlabs.fi unstable channel" |
| 8 | + build-release: |
| 9 | + uses: hatlabs/shared-workflows/.github/workflows/build-release.yml@main |
| 10 | + with: |
| 11 | + package-name: halpi2-daemon |
| 12 | + package-description: 'HALPI2 hardware daemon (Python implementation)' |
| 13 | + apt-component: hatlabs |
| 14 | + runs-on: ubuntu-latest-arm64 |
| 15 | + secrets: |
| 16 | + APT_REPO_PAT: ${{ secrets.APT_REPO_PAT }} |
0 commit comments