release #7
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: release | |
on: | |
push: | |
tags: | |
- 'v*' | |
jobs: | |
build-deb-rpm: | |
runs-on: ubuntu-latest | |
environment: release | |
steps: | |
- name: Checkout code repo | |
uses: actions/checkout@v4 | |
- name: Write release version | |
run: | | |
VERSION=${GITHUB_REF_NAME#v} | |
GITHASH=$(git rev-parse --short HEAD || echo "local") | |
GITDATE=$(date +"%a %d %b %Y %X %Z" -d @`git log -1 --format=%ct || echo "0"`) | |
echo "Building Version: $VERSION" | |
echo "commit hash: $GITHASH" | |
echo "commit date: $GITDATE" | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
echo "GITHASH=$GITHASH" >> $GITHUB_ENV | |
echo "GITDATE=$GITDATE" >> $GITHUB_ENV | |
echo "PACKAGE_NAME=${{ vars.PACKAGE_NAME }}" >> $GITHUB_ENV | |
echo "PACKAGE_AUTHOR=${{ vars.PACKAGE_AUTHOR }}" >> $GITHUB_ENV | |
echo "PACKAGE_EMAIL=${{ vars.PACKAGE_EMAIL }}" >> $GITHUB_ENV | |
- name: Install build deps | |
run: | | |
sudo add-apt-repository ppa:longsleep/golang-backports -y | |
sudo apt-get update | |
sudo apt-get install --no-install-recommends -y golang-1.21 dh-make devscripts dh-make-golang dh-golang build-essential fakeroot rpm tree | |
mkdir -p rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} | |
echo "%_topdir $(pwd)/rpmbuild" > ~/.rpmmacros | |
git clone https://github.com/openSUSE/golang-packaging.git /tmp/golang-packaging | |
pushd /tmp/golang-packaging | |
RPMCONFIGDIR=$(rpm --eval "%{_rpmconfigdir}") | |
RPMMACRODIR=$(rpm --eval "%{_rpmmacrodir}") | |
sudo install -m0755 golang.prov $RPMCONFIGDIR | |
sudo install -m0755 golang.req $RPMCONFIGDIR | |
sudo install -m0755 golang.sh $RPMCONFIGDIR | |
sudo install -m0644 macros.go $RPMMACRODIR | |
popd | |
- name: Build debian package | |
env: | |
PACKAGE_FORMAT: "dch" | |
run: | | |
set -x | |
sed -e "s/@NAME@/$PACKAGE_NAME/" -i debian/control | |
sed -e "s/@VERSION@/$VERSION/" \ | |
-e "s/@NAME@/$PACKAGE_NAME/" \ | |
-e "s/@HASH@/$GITHASH/" \ | |
-e "s/@DATE@/$GITDATE/" -i debian/rules | |
mv debian/_package_name_.install debian/${PACKAGE_NAME}.install | |
sed -e "s/@NAME@/$PACKAGE_NAME/g" -i debian/${PACKAGE_NAME}.install | |
scripts/keepachangelog2dch-rpm.sh CHANGELOG.md > debian/changelog | |
dpkg-buildpackage -uc -us -b | |
mv ../${PACKAGE_NAME}_${VERSION}_amd64.deb . | |
- name: Upload debian package as artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: deb-package | |
path: ${{ env.PACKAGE_NAME }}_${{ env.VERSION }}_amd64.deb | |
- name: Build RPM package | |
env: | |
PACKAGE_FORMAT: "rpm" | |
run: | | |
set -x | |
GITHASH=$(git rev-parse --short HEAD || echo "unknown") | |
GITDATE=$(date +"%a %d %b %Y %X %Z" -d @`git log -1 --format=%ct || echo "0"`) | |
scripts/clear-trailing-blanks.sh squirrelup.spec.in | | |
sed -e "s/@VERSION@/$VERSION/" \ | |
-e "s/@NAME@/$PACKAGE_NAME/" \ | |
-e "s/@HASH@/$GITHASH/" \ | |
-e "s/@DATE@/$GITDATE/" > squirrelup.spec | |
scripts/keepachangelog2dch-rpm.sh CHANGELOG.md >> squirrelup.spec | |
git archive --output=$(pwd)/rpmbuild/SOURCES/${PACKAGE_NAME}-${VERSION}.tar.gz --prefix=${PACKAGE_NAME}-${VERSION}/ HEAD | |
rpmbuild -bb --nodeps squirrelup.spec | |
mv rpmbuild/RPMS/x86_64/${PACKAGE_NAME}-${VERSION}-0.x86_64.rpm . | |
gzip -k ${PACKAGE_NAME}-${VERSION}-0.x86_64.rpm | |
- name: Upload RPM package as artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: rpm-package | |
path: ${{ env.PACKAGE_NAME }}-${{ env.VERSION }}-0.x86_64.rpm.gz | |
release: | |
runs-on: ubuntu-latest | |
needs: [build-deb-rpm] | |
environment: release | |
steps: | |
- name: Write release version | |
run: | | |
VERSION=${GITHUB_REF_NAME#v} | |
echo "Creating Release for Version: $VERSION" | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
echo "PACKAGE_NAME=${{ vars.PACKAGE_NAME }}" >> $GITHUB_ENV | |
- name: Checkout code repo | |
uses: actions/checkout@v4 | |
- name: Install deps | |
run: | | |
sudo apt-get update | |
sudo apt-get install --no-install-recommends -y tree | |
- name: Extract section of the changelog | |
id: extract-changelog | |
uses: sean0x42/markdown-extract@v2 | |
with: | |
file: CHANGELOG.md | |
pattern: "${{ env.VERSION }}" | |
- name: Write output to file | |
run: | | |
printf '${{ steps.extract-changelog.outputs.markdown }}' > changelog.md | |
if [ "$(cat changelog.md | wc -l)" -le "0" ]; then | |
echo "error: changelog is empty" | |
exit 1 | |
fi | |
#echo -e "\n\n## Commits:\n" >> changelog.md | |
#git log --pretty=format:"* [%s](${{ github.server_url }}/${{ github.repository }}/commit/%H)" >> changelog.md | |
cat changelog.md | |
- name: Download debian package from artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: deb-package | |
path: ${{ env.PACKAGE_NAME }}_${{ env.VERSION }}_amd64.deb | |
- name: Download RPM package from artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: rpm-package | |
path: ${{ env.PACKAGE_NAME }}-${{ env.VERSION }}-0.x86_64.rpm.gz | |
- name: Uncompress RPM package | |
run: | | |
tree | |
gunzip ${PACKAGE_NAME}-${VERSION}-0.x86_64.rpm.gz | |
- name: Create a release | |
uses: actions/create-release@v1 | |
id: create_release | |
with: | |
draft: false | |
prerelease: false | |
release_name: ${{ github.ref_name }} | |
tag_name: ${{ github.ref }} | |
body_path: changelog.md | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
- name: Upload debian package as release artifact | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ env.PACKAGE_NAME }}_${{ env.VERSION }}_amd64.deb | |
asset_name: ${{ env.PACKAGE_NAME }}_${{ env.VERSION }}_amd64.deb | |
asset_content_type: application/octet-stream | |
- name: Upload RPM package as release artifact | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ env.PACKAGE_NAME }}-${{ env.VERSION }}-0.x86_64.rpm | |
asset_name: ${{ env.PACKAGE_NAME }}-${{ env.VERSION }}-0.x86_64.rpm | |
asset_content_type: application/octet-stream |