1# This workflow tests installing our ubuntu and debian packages.
2name: APT packages
3on:
4  schedule:
5    # run daily 0:00 on master branch
6    - cron: '0 0 * * *'
7  push:
8    tags:
9    - '*'
10    branches:
11    - release_test
12jobs:
13  apt_tests:
14    name: APT ${{ matrix.image }} PG${{ matrix.pg }} ${{ matrix.license }}
15    runs-on: ubuntu-latest
16    container:
17      image: ${{ matrix.image }}
18      env:
19        DEBIAN_FRONTEND: noninteractive
20    strategy:
21      fail-fast: false
22      matrix:
23        # Debian images:  9 (stretch), 10 (buster), 11 (bullseye)
24        # Ubuntu images:  18.04 LTS (bionic), 19.10 (eoan), 20.04 LTS (focal), 21.04 (hirsute)
25        image: [ "debian:9-slim", "debian:10-slim", "debian:11-slim", "ubuntu:bionic", "ubuntu:focal", "ubuntu:hirsute"]
26        pg: [ 12, 13, 14 ]
27        license: [ "TSL", "Apache"]
28        include:
29          - license: Apache
30            pkg_suffix: "-oss"
31
32    steps:
33    - name: Add repositories
34      run: |
35        apt-get update
36        apt-get install -y wget lsb-release gnupg apt-transport-https sudo
37        echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -c -s)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
38        wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
39        image_type=$(lsb_release -i -s | tr '[:upper:]' '[:lower:]')
40        echo "deb https://packagecloud.io/timescale/timescaledb/${image_type}/ $(lsb_release -c -s) main" > /etc/apt/sources.list.d/timescaledb.list
41        wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | apt-key add -
42
43    - name: Install timescaledb
44      run: |
45        apt-get update
46        apt-get install -y --no-install-recommends timescaledb-2${{ matrix.pkg_suffix }}-postgresql-${{ matrix.pg }} timescaledb-tools
47        timescaledb-tune --quiet --yes
48
49    - name: List available versions
50      run: |
51        apt-cache show timescaledb-2${{ matrix.pkg_suffix }}-postgresql-${{ matrix.pg }} | grep -e Version: -e Depends: | tr '\n' ' ' | sed -e 's! Version: !\n!g' -e 's!Version: !!' -e 's!$!\n!'
52
53    - name: Show files in package
54      run: |
55        dpkg -L timescaledb-2${{ matrix.pkg_suffix }}-postgresql-${{ matrix.pg }}
56
57    - uses: actions/checkout@v2
58
59    - name: Read versions
60      id: versions
61      run: |
62        # read expected version from version.config
63        # version will only be a proper version in a release branch so we use update_from_version
64        # as fallback for master
65        if grep '^version = [0-9.]\+$' version.config; then
66          version=$(grep '^version = ' version.config | sed -e 's!^version = !!')
67        else
68          version=$(grep '^update_from_version = ' version.config | sed -e 's!^update_from_version = !!')
69        fi
70        echo "::set-output name=version::${version}"
71
72    - name: Test Installation
73      run: |
74        pg_ctlcluster ${{ matrix.pg }} main start
75        sudo -u postgres psql -X -c "CREATE EXTENSION timescaledb;SELECT extname,extversion,version() FROM pg_extension WHERE extname='timescaledb';"
76        installed_version=$(sudo -u postgres psql -X -t -c "SELECT extversion FROM pg_extension WHERE extname='timescaledb';" | sed -e 's! !!g')
77        if [ "${{ steps.versions.outputs.version }}" != "$installed_version" ];then
78          false
79        fi
80
81    - name: Test Downgrade
82      if: matrix.pg != 14
83      run: |
84        # since this runs nightly on master we have to get the previous version from the last released version and not current branch
85        prev_version=$(wget --quiet -O - https://raw.githubusercontent.com/timescale/timescaledb/${{ steps.versions.outputs.version }}/version.config | grep update_from_version | sed -e 's!update_from_version = !!')
86        sudo -u postgres psql -X -c "ALTER EXTENSION timescaledb UPDATE TO '${prev_version}';SELECT extname,extversion,version() FROM pg_extension WHERE extname='timescaledb';"
87        installed_version=$(sudo -u postgres psql -X -t -c "SELECT extversion FROM pg_extension WHERE extname='timescaledb';" | sed -e 's! !!g')
88        if [ "$prev_version" != "$installed_version" ];then
89          false
90        fi
91
92