[workflow] Fix pbuilder cache permission error
[platform/upstream/nnstreamer.git] / .github / workflows / pdebuild.yml
1 name: Build and unit test/ Pdebuild Ubuntu 22.04
2
3 # ${{ github.event.pull_request.commits }} : # commits in this PR
4 # - changed_file_list in GITHUB_ENV: the list of files updated in this pull-request.
5
6 ## @todo apply "cache" to pdebuilder cache, or create docker images ready for pdebuild
7
8 on:
9   pull_request:
10     branches: [ main ]
11
12 jobs:
13   build:
14
15     runs-on: ${{ matrix.os }}
16     strategy:
17       matrix:
18         #os: [ ubuntu-20.04, ubuntu-22.04 ]
19         ## ppa/nnstreamer's ubuntu 20.04 has gpgv error:
20         # E: Release signed by unknown key (key id CADA0F77901522B3)
21         #    The specified keyring /usr/share/keyrings/ubuntu-archive-keyring.gpg may be incorrect or out of date.
22         #    You can find the latest Debian release key at https://ftp-master.debian.org/keys.html
23         # E: debootstrap failed
24         # E: Tail of debootstrap.log:
25         # amd64: ok
26         # 2024-01-24 15:01:58 URL:http://ppa.launchpad.net/nnstreamer/ppa/ubuntu/dists/focal/InRelease [18035/18035] -> "/var/cache/pbuilder/build/10399/var/lib/apt/lists/partial/ppa.launchpad.net_nnstreamer_ppa_ubuntu_dists_focal_InRelease" [1]
27         # gpgv: Signature made Wed Jan 24 09:12:55 2024 UTC
28         # gpgv:                using RSA key 373A37D40E480F96524A4027CADA0F77901522B3
29         # gpgv: Can't check signature: No public key
30         # E: End of debootstrap.log
31         # W: Aborting with an error
32         os: [ ubuntu-22.04 ]
33         arch: [ amd64, arm64 ]
34         include:
35           - distroname: jammy
36             os: ubuntu-22.04
37         #  - distroname: focal
38         #    os: ubuntu-20.04
39
40     steps:
41     - uses: actions/checkout@v4
42       with:
43         ref: ${{ github.event.pull_request.head.sha }}
44         fetch-depth: -${{ github.event.pull_request.commits }}
45     - name: Check if rebuild required
46       ## @todo This should become a reusable workflow.
47       run: |
48         tmpfile=$(mktemp)
49         git show --pretty="format:" --name-only --diff-filter=AMRC ${{ github.event.pull_request.head.sha}} -${{ github.event.pull_request.commits }} | sort | uniq | awk NF > ${tmpfile}
50         echo "changed_file_list=${tmpfile}" >> "$GITHUB_ENV"
51         rebuild=`bash .github/workflows/check_if_rebuild_requires.sh ${tmpfile} debian | grep "REBUILD=YES" | wc -l`
52         echo "Rebuild required: ${rebuild}"
53         echo "rebuild=${rebuild}" >> "$GITHUB_ENV"
54     - uses: actions/setup-python@v1
55     - name: make cache dir for pbuilder
56       ## prevent permission error
57       run: sudo mkdir --mode a=rwx --parents /var/cache/pbuilder
58     - name: make cache key
59       if: env.rebuild == '1'
60       id: make-key
61       run: echo "cache_key=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
62       shell: bash
63     - name: cache pbuilder cache
64       id: cache-pbuilder
65       if: env.rebuild == '1'
66       uses: actions/cache@v3
67       with:
68         path: |
69           /var/cache/pbuilder/aptcache
70           /var/cache/pbuilder/base.tgz
71         key: ${{ steps.make-key.outputs.cache_key }}
72     - name: prepare pdebuild
73       if: env.rebuild == '1'
74       run: |
75         echo "Installing build tools"
76         sudo add-apt-repository ppa:nnstreamer/ppa
77         echo "::group::apt-get update && apt-get install"
78         sudo apt-get update && sudo apt-get install -y pbuilder debootstrap curl ubuntu-dev-tools qemu-user-static debian-archive-keyring ubuntu-keyring debhelper
79         echo "::endgroup::"
80         echo "DISTRIBUTION=${{ matrix.distroname }}" > ~/.pbuilderrc
81         echo "OTHERMIRROR=\"deb [trusted=yes] http://archive.ubuntu.com/ubuntu ${{ matrix.distroname }}-backports universe |deb [trusted=yes] http://ppa.launchpad.net/nnstreamer/ppa/ubuntu ${{ matrix.distroname }} main\"" >> ~/.pbuilderrc
82         cat ~/.pbuilderrc
83         sudo mkdir -p /root/
84         sudo ln -s ~/.pbuilderrc /root/
85     - name: make pbuilder base.tgz
86       if: steps.cache-pbuilder.outputs.cache-hit != 'true'
87       run: |
88         echo "=== pbuilder create"
89         echo "::group::pbuilder create --allow-untrusted"
90         sudo pbuilder create --allow-untrusted
91         echo "::endgroup::"
92         echo "=== pbuilder update"
93         echo "::group::pbuilder update --distribution ${{ matrix.distroname }}"
94         sudo pbuilder update --distribution ${{ matrix.distroname }}
95         echo "::endgroup"
96         echo "::group::pbuilder update"
97         sudo pbuilder update
98         echo "::endgroup"
99     - name: run pdebuild
100       if: env.rebuild == '1'
101       run: |
102         pdebuild --architecture ${{ matrix.arch }} -- --distribution ${{ matrix.distroname }}