2019-10-18 14:39:22 +00:00
|
|
|
---
|
|
|
|
name: build
|
|
|
|
|
2020-05-01 03:31:59 +00:00
|
|
|
on:
|
|
|
|
push:
|
|
|
|
pull_request:
|
|
|
|
repository_dispatch:
|
|
|
|
types: [apb]
|
2019-10-18 14:39:22 +00:00
|
|
|
|
2020-03-04 13:41:59 +00:00
|
|
|
env:
|
2021-07-09 17:34:16 +00:00
|
|
|
CURL_CACHE_DIR: ~/.cache/curl
|
2020-03-04 13:41:59 +00:00
|
|
|
PIP_CACHE_DIR: ~/.cache/pip
|
|
|
|
PRE_COMMIT_CACHE_DIR: ~/.cache/pre-commit
|
2021-07-09 17:34:16 +00:00
|
|
|
RUN_TMATE: ${{ secrets.RUN_TMATE }}
|
2020-03-04 13:41:59 +00:00
|
|
|
|
2019-10-18 14:39:22 +00:00
|
|
|
jobs:
|
2020-04-06 23:02:31 +00:00
|
|
|
lint:
|
2019-10-18 14:39:22 +00:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2021-08-27 18:59:29 +00:00
|
|
|
- uses: cisagov/setup-env-github-action@develop
|
2020-02-11 15:41:17 +00:00
|
|
|
- uses: actions/checkout@v2
|
2020-11-11 03:10:38 +00:00
|
|
|
- id: setup-python
|
|
|
|
uses: actions/setup-python@v2
|
2019-10-18 14:39:22 +00:00
|
|
|
with:
|
2020-10-07 16:41:47 +00:00
|
|
|
python-version: 3.9
|
2021-07-13 21:42:36 +00:00
|
|
|
# GO_VERSION and GOCACHE are used by the cache task, so the Go
|
|
|
|
# installation must happen before that.
|
|
|
|
- uses: actions/setup-go@v2
|
|
|
|
with:
|
|
|
|
go-version: '1.16'
|
|
|
|
- name: Store installed Go version
|
|
|
|
run: |
|
|
|
|
echo "GO_VERSION="\
|
|
|
|
"$(go version | sed 's/^go version go\([0-9.]\+\) .*/\1/')" \
|
|
|
|
>> $GITHUB_ENV
|
|
|
|
- name: Lookup Go cache directory
|
|
|
|
id: go-cache
|
|
|
|
run: |
|
|
|
|
echo "::set-output name=dir::$(go env GOCACHE)"
|
2020-11-20 17:22:39 +00:00
|
|
|
- uses: actions/cache@v2
|
|
|
|
env:
|
|
|
|
BASE_CACHE_KEY: "${{ github.job }}-${{ runner.os }}-\
|
2021-07-13 21:42:36 +00:00
|
|
|
py${{ steps.setup-python.outputs.python-version }}-\
|
2021-07-09 17:34:16 +00:00
|
|
|
go${{ env.GO_VERSION }}-\
|
|
|
|
packer${{ env.PACKER_VERSION }}-\
|
|
|
|
tf${{ env.TERRAFORM_VERSION }}-"
|
2019-11-05 19:27:20 +00:00
|
|
|
with:
|
2021-07-09 17:34:16 +00:00
|
|
|
# Note that the .terraform directory IS NOT included in the
|
|
|
|
# cache because if we were caching, then we would need to use
|
|
|
|
# the `-upgrade=true` option. This option blindly pulls down the
|
|
|
|
# latest modules and providers instead of checking to see if an
|
|
|
|
# update is required. That behavior defeats the benefits of caching.
|
|
|
|
# so there is no point in doing it for the .terraform directory.
|
2020-07-30 06:19:02 +00:00
|
|
|
path: |
|
|
|
|
${{ env.PIP_CACHE_DIR }}
|
|
|
|
${{ env.PRE_COMMIT_CACHE_DIR }}
|
2021-07-09 17:34:16 +00:00
|
|
|
${{ env.CURL_CACHE_DIR }}
|
2021-07-13 21:42:36 +00:00
|
|
|
${{ steps.go-cache.outputs.dir }}
|
2020-11-20 17:22:39 +00:00
|
|
|
key: "${{ env.BASE_CACHE_KEY }}\
|
2020-07-30 06:19:02 +00:00
|
|
|
${{ hashFiles('**/requirements-test.txt') }}-\
|
2020-09-03 20:31:23 +00:00
|
|
|
${{ hashFiles('**/requirements.txt') }}-\
|
2020-02-12 05:14:11 +00:00
|
|
|
${{ hashFiles('**/.pre-commit-config.yaml') }}"
|
2020-07-30 06:19:02 +00:00
|
|
|
restore-keys: |
|
2020-11-20 17:22:39 +00:00
|
|
|
${{ env.BASE_CACHE_KEY }}
|
2021-07-10 02:43:09 +00:00
|
|
|
- name: Setup curl cache
|
|
|
|
run: mkdir -p ${{ env.CURL_CACHE_DIR }}
|
2021-07-09 17:34:16 +00:00
|
|
|
- name: Install Packer
|
|
|
|
run: |
|
|
|
|
PACKER_ZIP="packer_${PACKER_VERSION}_linux_amd64.zip"
|
|
|
|
curl --output ${{ env.CURL_CACHE_DIR }}/"${PACKER_ZIP}" \
|
|
|
|
--time-cond ${{ env.CURL_CACHE_DIR }}/"${PACKER_ZIP}" \
|
|
|
|
--location \
|
|
|
|
"https://releases.hashicorp.com/packer/${PACKER_VERSION}/${PACKER_ZIP}"
|
2021-07-10 02:48:21 +00:00
|
|
|
sudo unzip -d /opt/packer \
|
2021-07-09 17:34:16 +00:00
|
|
|
${{ env.CURL_CACHE_DIR }}/"${PACKER_ZIP}"
|
2021-07-10 02:48:21 +00:00
|
|
|
sudo mv /usr/local/bin/packer /usr/local/bin/packer-default
|
|
|
|
sudo ln -s /opt/packer/packer /usr/local/bin/packer
|
2021-08-10 03:42:42 +00:00
|
|
|
- uses: hashicorp/setup-terraform@v1
|
|
|
|
with:
|
|
|
|
terraform_version: ${{ env.TERRAFORM_VERSION }}
|
2021-07-13 21:42:36 +00:00
|
|
|
- name: Install shfmt
|
|
|
|
run: go install mvdan.cc/sh/v3/cmd/shfmt@${SHFMT_VERSION}
|
2021-07-09 17:34:16 +00:00
|
|
|
- name: Install Terraform-docs
|
2021-07-11 02:36:45 +00:00
|
|
|
run: |
|
2021-07-13 21:02:13 +00:00
|
|
|
go install \
|
2021-07-11 02:36:45 +00:00
|
|
|
github.com/terraform-docs/terraform-docs@${TERRAFORM_DOCS_VERSION}
|
2019-10-18 14:39:22 +00:00
|
|
|
- name: Install dependencies
|
|
|
|
run: |
|
|
|
|
python -m pip install --upgrade pip
|
2020-02-18 23:04:06 +00:00
|
|
|
pip install --upgrade --requirement requirements-test.txt
|
2020-04-06 23:02:31 +00:00
|
|
|
- name: Set up pre-commit hook environments
|
2020-04-06 17:47:18 +00:00
|
|
|
run: pre-commit install-hooks
|
2019-10-18 14:39:22 +00:00
|
|
|
- name: Run pre-commit on all files
|
|
|
|
run: pre-commit run --all-files
|
2021-07-09 17:34:16 +00:00
|
|
|
- name: Setup tmate debug session
|
|
|
|
uses: mxschmitt/action-tmate@v3
|
|
|
|
if: env.RUN_TMATE
|