Debian Codegraph @

.github/workflows/build-packages.yml

raw symbols SCIP
1 name: Build Packages
2
3 # this covers the following use cases:
4 #
5 # 1. build snapshot packages for every push to any branch
6 # 2. publish packages as "ReaR Snapshot" for every push to master
7 # 3. build official packages for every push of a tag named release/* and publish as "ReaR Release"
8
9 on: push
10
11 env:
12 # Set RELEASE to the release tag or to snapshot
13 RELEASE: ${{ startsWith(github.ref, 'refs/tags/release/') && github.ref_name || 'no-release' }}
14
15 concurrency:
16 group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
17 cancel-in-progress: true
18
19 jobs:
20 build:
21 runs-on: ubuntu-latest
22 permissions:
23 contents: write
24 id-token: write
25 steps:
26 - uses: actions/checkout@v4
27 with:
28 fetch-depth: 0
29
30 - name: Extract release version
31 # Set release version and filename from the release tag
32 # e.g. 2.8.0 -> RELEASE_VERSION=2.8.0 RELEASE_FILENAME=release-2.8.0
33 if: startsWith(env.RELEASE, 'release')
34 run: |
35 tee -a $GITHUB_ENV <<< "RELEASE_VERSION=${RELEASE#release/}"
36 tee -a $GITHUB_ENV <<< "RELEASE_FILENAME=${RELEASE//\//-}"
37
38 - name: Setup build environment
39 run: sudo apt-get -qq update && sudo apt-get -qq install asciidoctor
40
41 - name: Build Snapshot dist archive
42 if: env.RELEASE == 'no-release'
43 run: make dist
44
45 # check if the release version matches the source version before building official release dist archive
46 - name: Check and build Release dist archive
47 if: startsWith(env.RELEASE, 'release')
48 run: |
49 if [ -z "$RELEASE_VERSION" ] ; then
50 echo "::error::Release version not set in RELEASE_VERSION"
51 exit 1
52 fi
53
54 SOURCE_VERSION=$(make version OFFICIAL=1)
55 if [ "$SOURCE_VERSION" != "$RELEASE_VERSION" ] ; then
56 # Find the line where VERSION is set
57 VERSION_LINE=$(grep -n "^readonly VERSION=" usr/sbin/rear | cut -d: -f1)
58 echo "### Version Check Failed" >> $GITHUB_STEP_SUMMARY
59 echo "* Expected version: $RELEASE_VERSION" >> $GITHUB_STEP_SUMMARY
60 echo "* Current version: $SOURCE_VERSION" >> $GITHUB_STEP_SUMMARY
61 echo "::error file=usr/sbin/rear,line=$VERSION_LINE::Version mismatch: Source version in rear script ($SOURCE_VERSION) does not match release tag version ($RELEASE_VERSION)"
62 exit 1
63 fi
64
65 make dist OFFICIAL=1
66
67 - name: Prepare Docker images
68 run: tools/run-in-docker -- --patch --continue-and-record-successful images
69
70 - name: List available Docker images
71 if: always()
72 run: |
73 test -r images && cat images || :
74
75 - name: Build snapshot packages via Docker
76 if: env.RELEASE == 'no-release'
77 # make package only for images that we patched successfully - continue despite errors
78 run: tools/run-in-docker $(<images) -- 'make package || tar -cvzf dist-all/build-$HOSTNAME.tar.gz /var/tmp/build-rear*'
79
80 - name: Build release packages via Docker
81 if: startsWith(env.RELEASE, 'release')
82 # make package for all images that we support - fail on errors
83 # we need to specify again OFFICIAL=1 as the Makefile determines the version to use before
84 # building the package, and without it wouldn't match with the dist archive created earlier
85 # TODO: make package should be able to determine the version from the dist archive instead
86 run: tools/run-in-docker -- make package OFFICIAL=1
87
88 - name: List dist-all
89 run: |
90 test -d dist-all && ls -lR dist-all || :
91 if: always()
92
93 - name: Upload Artifacts
94 if: always()
95 uses: actions/upload-artifact@v4
96 with:
97 name: ReaR Packages ${{ github.head_ref || env.RELEASE_FILENAME || github.ref_name }} ${{ github.sha }}
98 path: dist-all/*
99 retention-days: 7
100
101 - name: Check rear dump
102 run: tools/run-in-docker $(<images) -- rear dump
103
104 - name: Create Snapshot Archives and Update GitHub Snapshot Release
105 # only create snapshot release for master branch
106 if: github.ref == 'refs/heads/master'
107 env:
108 GITHUB_TOKEN: ${{ github.token }}
109 run: |
110 #
111 set -e
112
113 # put commit details into ZIP comment as the files always have the same names
114 COMMENT=$(git show -s --format="ReaR snapshot %h %ci%nhttps://github.com/rear/rear/tree/%H")
115
116 for distro in dist-all/* ; do
117 test -d "$distro" || continue
118 zip -0 -j -z "$distro.zip" "$distro"/* <<< "$COMMENT"
119 done
120
121 gh release delete snapshot -y || :
122 git push --delete origin snapshot || :
123 gh release create snapshot \
124 --target ${{ github.sha }} \
125 --title "ReaR Snapshot $(git show -s --format="%ci")" \
126 --notes "Automatically built installation packages for testing purposes" \
127 dist-all/*.zip dist/*.tar.gz
128
129 - name: Create Release Archives and Update GitHub Release
130 if: startsWith(env.RELEASE, 'release')
131 env:
132 GITHUB_TOKEN: ${{ github.token }}
133 run: |
134 #
135 set -e
136
137 # put commit details into ZIP comment as the files always have the same names
138 COMMENT=$(git show -s --format="ReaR release version $RELEASE_VERSION %h %ci%nhttps://github.com/rear/rear/tree/%H")
139
140 for distro in dist-all/* ; do
141 test -d "$distro" || continue
142 zip -0 -j -z "$distro.zip" "$distro"/* <<< "$COMMENT"
143 done
144
145 dist_archive=$(ls -1 dist/*.tar.gz)
146 gh release create "$RELEASE" \
147 --title "ReaR Release $RELEASE_VERSION ($(git show -s --format="%cs"))" \
148 --generate-notes \
149 dist-all/*.zip "${dist_archive}#Official ReaR source distribution ${dist_archive##*/}"