|
| 1 | +--- |
| 2 | +name: build |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + pull_request: |
| 7 | + repository_dispatch: |
| 8 | + types: [apb] |
| 9 | + |
| 10 | +env: |
| 11 | + CURL_CACHE_DIR: ~/.cache/curl |
| 12 | + PIP_CACHE_DIR: ~/.cache/pip |
| 13 | + PRE_COMMIT_CACHE_DIR: ~/.cache/pre-commit |
| 14 | + RUN_TMATE: ${{ secrets.RUN_TMATE }} |
| 15 | + |
| 16 | +jobs: |
| 17 | + lint: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - id: setup-env |
| 21 | + uses: cisagov/setup-env-github-action@develop |
| 22 | + - uses: actions/checkout@v2 |
| 23 | + - id: setup-python |
| 24 | + uses: actions/setup-python@v2 |
| 25 | + with: |
| 26 | + python-version: 3.9 |
| 27 | + # We need the Go version and Go cache location for the actions/cache step, |
| 28 | + # so the Go installation must happen before that. |
| 29 | + - uses: actions/setup-go@v2 |
| 30 | + with: |
| 31 | + go-version: '1.16' |
| 32 | + - name: Store installed Go version |
| 33 | + id: go-version |
| 34 | + run: | |
| 35 | + echo "::set-output name=version::"\ |
| 36 | + "$(go version | sed 's/^go version go\([0-9.]\+\) .*/\1/')" |
| 37 | + - name: Lookup Go cache directory |
| 38 | + id: go-cache |
| 39 | + run: | |
| 40 | + echo "::set-output name=dir::$(go env GOCACHE)" |
| 41 | + - uses: actions/cache@v2 |
| 42 | + env: |
| 43 | + BASE_CACHE_KEY: "${{ github.job }}-${{ runner.os }}-\ |
| 44 | + py${{ steps.setup-python.outputs.python-version }}-\ |
| 45 | + go${{ steps.go-version.outputs.version }}-\ |
| 46 | + packer${{ steps.setup-env.outputs.packer-version }}-\ |
| 47 | + tf${{ steps.setup-env.outputs.terraform-version }}-" |
| 48 | + with: |
| 49 | + # Note that the .terraform directory IS NOT included in the |
| 50 | + # cache because if we were caching, then we would need to use |
| 51 | + # the `-upgrade=true` option. This option blindly pulls down the |
| 52 | + # latest modules and providers instead of checking to see if an |
| 53 | + # update is required. That behavior defeats the benefits of caching. |
| 54 | + # so there is no point in doing it for the .terraform directory. |
| 55 | + path: | |
| 56 | + ${{ env.PIP_CACHE_DIR }} |
| 57 | + ${{ env.PRE_COMMIT_CACHE_DIR }} |
| 58 | + ${{ env.CURL_CACHE_DIR }} |
| 59 | + ${{ steps.go-cache.outputs.dir }} |
| 60 | + # We do not use '**/setup.py' in the cache key so only the 'setup.py' |
| 61 | + # file in the root of the repository is used. This is in case a Python |
| 62 | + # package were to have a 'setup.py' as part of its internal codebase. |
| 63 | + key: "${{ env.BASE_CACHE_KEY }}\ |
| 64 | + ${{ hashFiles('**/requirements-test.txt') }}-\ |
| 65 | + ${{ hashFiles('**/requirements.txt') }}-\ |
| 66 | + ${{ hashFiles('**/.pre-commit-config.yaml') }}-\ |
| 67 | + ${{ hashFiles('setup.py') }}" |
| 68 | + restore-keys: | |
| 69 | + ${{ env.BASE_CACHE_KEY }} |
| 70 | + - name: Setup curl cache |
| 71 | + run: mkdir -p ${{ env.CURL_CACHE_DIR }} |
| 72 | + - name: Install Packer |
| 73 | + env: |
| 74 | + PACKER_VERSION: ${{ steps.setup-env.outputs.packer-version }} |
| 75 | + run: | |
| 76 | + PACKER_ZIP="packer_${PACKER_VERSION}_linux_amd64.zip" |
| 77 | + curl --output ${{ env.CURL_CACHE_DIR }}/"${PACKER_ZIP}" \ |
| 78 | + --time-cond ${{ env.CURL_CACHE_DIR }}/"${PACKER_ZIP}" \ |
| 79 | + --location \ |
| 80 | + "https://releases.hashicorp.com/packer/${PACKER_VERSION}/${PACKER_ZIP}" |
| 81 | + sudo unzip -d /opt/packer \ |
| 82 | + ${{ env.CURL_CACHE_DIR }}/"${PACKER_ZIP}" |
| 83 | + sudo mv /usr/local/bin/packer /usr/local/bin/packer-default |
| 84 | + sudo ln -s /opt/packer/packer /usr/local/bin/packer |
| 85 | + - uses: hashicorp/setup-terraform@v1 |
| 86 | + with: |
| 87 | + terraform_version: ${{ steps.setup-env.outputs.terraform-version }} |
| 88 | + - name: Install shfmt |
| 89 | + env: |
| 90 | + PACKAGE_URL: mvdan.cc/sh/v3/cmd/shfmt |
| 91 | + PACKAGE_VERSION: ${{ steps.setup-env.outputs.shfmt-version }} |
| 92 | + run: go install ${PACKAGE_URL}@${PACKAGE_VERSION} |
| 93 | + - name: Install Terraform-docs |
| 94 | + env: |
| 95 | + PACKAGE_URL: github.com/terraform-docs/terraform-docs |
| 96 | + PACKAGE_VERSION: ${{ steps.setup-env.outputs.terraform-docs-version }} |
| 97 | + run: go install ${PACKAGE_URL}@${PACKAGE_VERSION} |
| 98 | + - name: Install dependencies |
| 99 | + run: | |
| 100 | + python -m pip install --upgrade pip |
| 101 | + pip install --upgrade --requirement requirements-test.txt |
| 102 | + - name: Set up pre-commit hook environments |
| 103 | + run: pre-commit install-hooks |
| 104 | + - name: Run pre-commit on all files |
| 105 | + run: pre-commit run --all-files |
| 106 | + - name: Setup tmate debug session |
| 107 | + uses: mxschmitt/action-tmate@v3 |
| 108 | + if: env.RUN_TMATE |
| 109 | + test: |
| 110 | + runs-on: ubuntu-latest |
| 111 | + strategy: |
| 112 | + fail-fast: false |
| 113 | + matrix: |
| 114 | + python-version: |
| 115 | + - "3.6" |
| 116 | + - "3.7" |
| 117 | + - "3.8" |
| 118 | + - "3.9" |
| 119 | + - "3.10" |
| 120 | + steps: |
| 121 | + - uses: actions/checkout@v2 |
| 122 | + - id: setup-python |
| 123 | + uses: actions/setup-python@v2 |
| 124 | + with: |
| 125 | + python-version: ${{ matrix.python-version }} |
| 126 | + - uses: actions/cache@v2 |
| 127 | + env: |
| 128 | + BASE_CACHE_KEY: "${{ github.job }}-${{ runner.os }}-\ |
| 129 | + py${{ steps.setup-python.outputs.python-version }}-" |
| 130 | + with: |
| 131 | + path: ${{ env.PIP_CACHE_DIR }} |
| 132 | + # We do not use '**/setup.py' in the cache key so only the 'setup.py' |
| 133 | + # file in the root of the repository is used. This is in case a Python |
| 134 | + # package were to have a 'setup.py' as part of its internal codebase. |
| 135 | + key: "${{ env.BASE_CACHE_KEY }}\ |
| 136 | + ${{ hashFiles('**/requirements-test.txt') }}-\ |
| 137 | + ${{ hashFiles('**/requirements.txt') }}-\ |
| 138 | + ${{ hashFiles('setup.py') }}" |
| 139 | + restore-keys: | |
| 140 | + ${{ env.BASE_CACHE_KEY }} |
| 141 | + - name: Install dependencies |
| 142 | + run: | |
| 143 | + python -m pip install --upgrade pip |
| 144 | + pip install --upgrade --requirement requirements-test.txt |
| 145 | + - name: Run tests |
| 146 | + env: |
| 147 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 148 | + run: pytest |
| 149 | + - name: Upload coverage report |
| 150 | + run: coveralls |
| 151 | + env: |
| 152 | + COVERALLS_FLAG_NAME: "py${{ matrix.python-version }}" |
| 153 | + COVERALLS_PARALLEL: true |
| 154 | + COVERALLS_SERVICE_NAME: github |
| 155 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 156 | + if: success() |
| 157 | + - name: Setup tmate debug session |
| 158 | + uses: mxschmitt/action-tmate@v3 |
| 159 | + if: env.RUN_TMATE |
| 160 | + coveralls-finish: |
| 161 | + runs-on: ubuntu-latest |
| 162 | + needs: test |
| 163 | + steps: |
| 164 | + - uses: actions/checkout@v2 |
| 165 | + - id: setup-python |
| 166 | + uses: actions/setup-python@v2 |
| 167 | + with: |
| 168 | + python-version: 3.9 |
| 169 | + - uses: actions/cache@v2 |
| 170 | + env: |
| 171 | + BASE_CACHE_KEY: "${{ github.job }}-${{ runner.os }}-\ |
| 172 | + py${{ steps.setup-python.outputs.python-version }}-" |
| 173 | + with: |
| 174 | + path: ${{ env.PIP_CACHE_DIR }} |
| 175 | + # We do not use '**/setup.py' in the cache key so only the 'setup.py' |
| 176 | + # file in the root of the repository is used. This is in case a Python |
| 177 | + # package were to have a 'setup.py' as part of its internal codebase. |
| 178 | + key: "${{ env.BASE_CACHE_KEY }}\ |
| 179 | + ${{ hashFiles('**/requirements-test.txt') }}-\ |
| 180 | + ${{ hashFiles('**/requirements.txt') }}-\ |
| 181 | + ${{ hashFiles('setup.py') }}" |
| 182 | + restore-keys: | |
| 183 | + ${{ env.BASE_CACHE_KEY }} |
| 184 | + - name: Install dependencies |
| 185 | + run: | |
| 186 | + python -m pip install --upgrade pip |
| 187 | + pip install --upgrade --requirement requirements-test.txt |
| 188 | + - name: Finished coveralls reports |
| 189 | + run: coveralls --finish |
| 190 | + env: |
| 191 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 192 | + - name: Setup tmate debug session |
| 193 | + uses: mxschmitt/action-tmate@v3 |
| 194 | + if: env.RUN_TMATE |
| 195 | + build: |
| 196 | + runs-on: ubuntu-latest |
| 197 | + needs: [lint, test] |
| 198 | + strategy: |
| 199 | + fail-fast: false |
| 200 | + matrix: |
| 201 | + python-version: |
| 202 | + - "3.6" |
| 203 | + - "3.7" |
| 204 | + - "3.8" |
| 205 | + - "3.9" |
| 206 | + - "3.10" |
| 207 | + steps: |
| 208 | + - uses: actions/checkout@v2 |
| 209 | + - id: setup-python |
| 210 | + uses: actions/setup-python@v2 |
| 211 | + with: |
| 212 | + python-version: ${{ matrix.python-version }} |
| 213 | + - uses: actions/cache@v2 |
| 214 | + env: |
| 215 | + BASE_CACHE_KEY: "${{ github.job }}-${{ runner.os }}-\ |
| 216 | + py${{ steps.setup-python.outputs.python-version }}-" |
| 217 | + with: |
| 218 | + path: ${{ env.PIP_CACHE_DIR }} |
| 219 | + # We do not use '**/setup.py' in the cache key so only the 'setup.py' |
| 220 | + # file in the root of the repository is used. This is in case a Python |
| 221 | + # package were to have a 'setup.py' as part of its internal codebase. |
| 222 | + key: "${{ env.BASE_CACHE_KEY }}\ |
| 223 | + ${{ hashFiles('**/requirements.txt') }}-\ |
| 224 | + ${{ hashFiles('setup.py') }}" |
| 225 | + restore-keys: | |
| 226 | + ${{ env.BASE_CACHE_KEY }} |
| 227 | + - name: Install dependencies |
| 228 | + run: | |
| 229 | + python -m pip install --upgrade pip wheel |
| 230 | + pip install --upgrade --requirement requirements.txt |
| 231 | + - name: Build artifacts |
| 232 | + run: python3 setup.py sdist bdist_wheel |
| 233 | + - name: Upload artifacts |
| 234 | + uses: actions/upload-artifact@v2 |
| 235 | + with: |
| 236 | + name: dist-${{ matrix.python-version }} |
| 237 | + path: dist |
| 238 | + - name: Setup tmate debug session |
| 239 | + uses: mxschmitt/action-tmate@v3 |
| 240 | + if: env.RUN_TMATE |
0 commit comments