1+ name : Release Package
2+
3+ on :
4+ push :
5+ tags :
6+ - ' v*.*.*'
7+
8+ jobs :
9+ build :
10+ runs-on : ubuntu-latest
11+ strategy :
12+ matrix :
13+ arch : [amd64, arm64]
14+ include :
15+ - arch : amd64
16+ goarch : amd64
17+ deb_arch : amd64
18+ rpm_arch : x86_64
19+ - arch : arm64
20+ goarch : arm64
21+ deb_arch : arm64
22+ rpm_arch : aarch64
23+ steps :
24+ - name : Checkout code
25+ uses : actions/checkout@v3
26+
27+ - name : Set up Go
28+ uses : actions/setup-go@v4
29+ with :
30+ go-version : ' 1.20'
31+
32+ - name : Set up Ruby
33+ uses : ruby/setup-ruby@v1
34+ with :
35+ ruby-version : ' 3.0'
36+
37+ - name : Install FPM
38+ run : gem install fpm
39+
40+ - name : Get the version
41+ id : get_version
42+ run : echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
43+
44+ - name : Build binary for ${{ matrix.arch }}
45+ run : GOARCH=${{ matrix.goarch }} go build -o agent
46+
47+ - name : Make scripts executable
48+ run : chmod +x scripts/postinstall.sh
49+
50+ - name : Package DEB for ${{ matrix.arch }}
51+ run : |
52+ fpm -s dir -t deb -n agent -v ${{ env.VERSION }} \
53+ --architecture ${{ matrix.deb_arch }} \
54+ --description "Remote file opener via REST API" \
55+ --maintainer "Sai Sanjay <saisanjay7660@gmail.com>" \
56+ --depends "apt" \
57+ --after-install scripts/postinstall.sh \
58+ --deb-pre-depends "apt" \
59+ ./agent=/usr/local/bin/agent \
60+ ./agent.service=/lib/systemd/system/agent.service \
61+ ./dependencies.txt=/usr/share/agent/dependencies.txt
62+
63+ - name : Package RPM for ${{ matrix.arch }}
64+ run : |
65+ fpm -s dir -t rpm -n agent -v ${{ env.VERSION }} \
66+ --architecture ${{ matrix.rpm_arch }} \
67+ --description "Remote file opener via REST API" \
68+ --maintainer "Sai Sanjay <saisanjay7660@gmail.com>" \
69+ --depends "yum" \
70+ --after-install scripts/postinstall.sh \
71+ ./agent=/usr/local/bin/agent \
72+ ./agent.service=/usr/lib/systemd/system/agent.service \
73+ ./dependencies.txt=/usr/share/agent/dependencies.txt
74+
75+ - name : Upload artifacts
76+ uses : actions/upload-artifact@v3
77+ with :
78+ name : packages-${{ matrix.arch }}
79+ path : |
80+ agent_${{ env.VERSION }}_${{ matrix.deb_arch }}.deb
81+ agent-${{ env.VERSION }}-1.${{ matrix.rpm_arch }}.rpm
82+
83+ release :
84+ needs : build
85+ runs-on : ubuntu-latest
86+ steps :
87+ - name : Download all artifacts
88+ uses : actions/download-artifact@v3
89+ with :
90+ path : packages
91+
92+ - name : Display structure of downloaded files
93+ run : ls -R packages
94+
95+ - name : Flatten directory structure
96+ run : |
97+ mkdir -p release_files
98+ find packages -type f -name "*.deb" -o -name "*.rpm" | xargs -I {} cp {} release_files/
99+
100+ - name : Create "any" and "noarch" packages
101+ run : |
102+ # For demonstration, create symlinks to the amd64 packages
103+ # In a real scenario, you might need to create truly architecture-independent packages
104+ cd release_files
105+ cp agent_${{ env.VERSION }}_amd64.deb agent_${{ env.VERSION }}_any.deb
106+ cp agent-${{ env.VERSION }}-1.x86_64.rpm agent-${{ env.VERSION }}-1.noarch.rpm
107+
108+ - name : Create Release
109+ uses : softprops/action-gh-release@v1
110+ with :
111+ files : release_files/*
112+ draft : false
113+ prerelease : false
114+ env :
115+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments