Skip to content

Commit

Permalink
ci: Send email if the reproducible build process fails
Browse files Browse the repository at this point in the history
Changelog-None.
  • Loading branch information
ShahanaFarooqui committed Dec 3, 2024
1 parent ebebb81 commit 2c84244
Showing 1 changed file with 110 additions and 38 deletions.
148 changes: 110 additions & 38 deletions .github/workflows/repro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,133 @@ jobs:
version: ['focal', 'jammy', 'noble']
steps:
- name: Git checkout
id: repo_chackout
uses: actions/checkout@v4

- name: Build environment setup
id: environment_setup
shell: bash
run: |
echo "Building base image for ${{ matrix.version }}"
sudo docker run --rm -v $(pwd):/build ubuntu:${{ matrix.version }} bash -c "\
apt-get update && \
apt-get install -y debootstrap && \
debootstrap ${{ matrix.version }} /build/${{ matrix.version }}"
sudo tar -C ${{ matrix.version }} -c . | docker import - ${{ matrix.version }}
{
echo "STEP=Build environment setup" >> "$GITHUB_ENV"
echo "Building base image for ${{ matrix.version }}"
sudo docker run --rm -v $(pwd):/build ubuntu:${{ matrix.version }} bash -c "\
apt-get update && \
apt-get install -y debootstrap && \
debootstrap ${{ matrix.version }} /build/${{ matrix.version }}"
sudo tar -C ${{ matrix.version }} -c . | docker import - ${{ matrix.version }}
} > command.log 2>&1 || {
echo "ERROR<<EOF" >> "$GITHUB_ENV"
echo "$(cat command.log)" >> "$GITHUB_ENV"
echo "EOF" >> "$GITHUB_ENV"
exit 1
}
- name: Builder image setup
run: docker build -t cl-repro-${{ matrix.version }} - < contrib/reprobuild/Dockerfile.${{ matrix.version }}
id: builder_image_setup
shell: bash
run: |
{
echo "STEP=Builder image setup" >> "$GITHUB_ENV"
docker build -t cl-repro-${{ matrix.version }} - < contrib/reprobuild/Dockerfile.${{ matrix.version }}
} > command.log 2>&1 || {
echo "ERROR<<EOF" >> "$GITHUB_ENV"
echo "$(cat command.log)" >> "$GITHUB_ENV"
echo "EOF" >> "$GITHUB_ENV"
exit 1
}
- name: Build reproducible image and store Git state
id: repro_image_setup
shell: bash
run: |
# Create repro directory.
mkdir $GITHUB_WORKSPACE/repro
{
echo "STEP=Build reproducible image and store Git state" >> "$GITHUB_ENV"
# Perform the repro build.
docker run --name cl-build -v $GITHUB_WORKSPACE:/repo -e FORCE_MTIME=$(date +%F) -t cl-repro-${{ matrix.version }}
# Create repro directory.
mkdir $GITHUB_WORKSPACE/repro
# Commit the image in order to inspect the build later.
docker commit cl-build cl-repro
# Perform the repro build.
docker run --name cl-build -v $GITHUB_WORKSPACE:/repo -e FORCE_MTIME=$(date +%F) -t cl-repro-${{ matrix.version }}
# Inspect the version.
docker run --rm -v $GITHUB_WORKSPACE:/repo -t cl-repro bash -c "make version > /repo/repro/version.txt"
# Commit the image in order to inspect the build later.
docker commit cl-build cl-repro
# Inspect the Git tree state.
docker run --rm -v $GITHUB_WORKSPACE:/repo -t cl-repro bash -c "\
git --no-pager status > /repo/repro/git.log && \
git --no-pager diff >> /repo/repro/git.log"
# Inspect the version.
docker run --rm -v $GITHUB_WORKSPACE:/repo -t cl-repro bash -c "make version > /repo/repro/version.txt"
# Change permissions on the repro files for access by the runner environment.
sudo chown -R runner $GITHUB_WORKSPACE/repro
# Inspect the Git tree state.
docker run --rm -v $GITHUB_WORKSPACE:/repo -t cl-repro bash -c "\
git --no-pager status > /repo/repro/git.log && \
git --no-pager diff >> /repo/repro/git.log"
# Change permissions on the repro files for access by the runner environment.
sudo chown -R runner $GITHUB_WORKSPACE/repro
} > command.log 2>&1 || {
echo "ERROR<<EOF" >> "$GITHUB_ENV"
echo "$(cat command.log)" >> "$GITHUB_ENV"
echo "EOF" >> "$GITHUB_ENV"
exit 1
}
- name: Assert clean version
id: assert_version
shell: bash
run: |
echo 'Version:'
cat repro/version.txt
echo -e
reprofile=$(ls repro/clightning-*)
echo 'Repro file:'
ls -al repro/clightning-*
echo -e
{
echo "STEP=Assert clean version" >> "$GITHUB_ENV"
echo 'Version:'
cat repro/version.txt
echo -e
if [ -n "$(cat repro/version.txt | sed -n '/-modded/p')" ] || \
[ -n "$(echo $reprofile | sed -n '/-modded/p')" ]
then
echo "Git Status and Diff:"
cat repro/git.log
reprofile=$(ls repro/clightning-*)
echo 'Repro file:'
ls -al repro/clightning-*
echo -e
echo 'Error: Repository modded / dirty tree.'
if [ -n "$(cat repro/version.txt | sed -n '/-modded/p')" ] || \
[ -n "$(echo $reprofile | sed -n '/-modded/p')" ]
then
echo "Git Status and Diff:"
cat repro/git.log
echo -e
echo 'Error: Repository modded / dirty tree.'
exit 1
else
echo 'Success! Clean Build.'
fi
} > command.log 2>&1 || {
echo "ERROR<<EOF" >> "$GITHUB_ENV"
echo "$(cat command.log)" >> "$GITHUB_ENV"
echo "EOF" >> "$GITHUB_ENV"
exit 1
else
echo 'Success! Clean Build.'
fi
}
- name: Send email on failure
id: send_email
if: ${{ failure() }}
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.gmail.com
server_port: 587
username: ${{ secrets.EMAIL_USERNAME }}
password: ${{ secrets.EMAIL_PASSWORD }}
from: ${{ secrets.EMAIL_USERNAME }}
to: ${{ vars.DISTRIBUTION_LIST }}
subject: "CI Failure: Step ${{ env.STEP }} failed for distro ${{ matrix.version }}"
convert_markdown: true
html_body: |
<html>
<body>
<p><strong>Failure Details:</strong></p>
<ul>
<li><strong>Workflow:</strong> ${{ github.workflow }}</li>
<li><strong>Event:</strong> ${{ github.event_name }}</li>
<li><strong>Job:</strong> ${{ github.job }}</li>
<li><strong>Distro:</strong> ${{ matrix.version }}</li>
<li><strong>Step:</strong> ${{ env.STEP }}</li>
<li><strong>URL:</strong> <a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}">${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}</a></li>
<li><strong>Reason:</strong> <pre>${{ env.ERROR }}</pre></li>
</ul>
</body>
</html>

0 comments on commit 2c84244

Please sign in to comment.