Update github actions to use nvmrc file for node versioning #1463
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PR | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
lint: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- run: | | |
echo "PYTHON_VERSION=$(cat .python-version)" >> $GITHUB_ENV | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- uses: actions/setup-node@v3 | |
with: | |
node-version-file: ".nvmrc" | |
cache: "yarn" | |
- run: | | |
echo "PYTHON_VERSION=$(python -c 'import platform; print(platform.python_version())')" >> $GITHUB_ENV | |
- name: Install yarn deps | |
run: yarn install | |
- name: Install Poetry | |
uses: snok/install-poetry@v1 | |
with: | |
version: 1.3.2 | |
virtualenvs-create: true | |
virtualenvs-in-project: false | |
virtualenvs-path: ~/.virtualenvs | |
- name: Cache Poetry virtualenv | |
uses: actions/cache@v3 | |
id: cache-virtualenv | |
with: | |
path: ~/.virtualenvs | |
key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-virtualenvs-${{ hashFiles('poetry.lock') }} | |
- name: Install virtual environment | |
if: steps.cache-virtualenv.outputs.cache-hit != 'true' | |
run: poetry install | |
- name: Lint Python | |
run: make lint | |
test-unit: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- run: | |
echo "PYTHON_VERSION=$(cat .python-version)" >> $GITHUB_ENV | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- uses: actions/setup-node@v3 | |
with: | |
node-version-file: ".nvmrc" | |
cache: "yarn" | |
- run: | | |
echo "PYTHON_VERSION=$(python -c 'import platform; print(platform.python_version())')" >> $GITHUB_ENV | |
- name: Install yarn deps | |
run: yarn install | |
- name: Running yarn tests | |
run: make test-yarn | |
- name: Install Poetry | |
uses: snok/install-poetry@v1 | |
with: | |
version: 1.3.2 | |
virtualenvs-create: true | |
virtualenvs-in-project: false | |
virtualenvs-path: ~/.virtualenvs | |
- name: Cache Poetry virtualenv | |
uses: actions/cache@v3 | |
id: cache-virtualenv | |
with: | |
path: ~/.virtualenvs | |
key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-virtualenvs-${{ hashFiles('poetry.lock') }} | |
- name: Install virtual environment | |
if: steps.cache-virtualenv.outputs.cache-hit != 'true' | |
run: poetry install | |
- name: Running unit tests | |
run: make test-unit | |
docker-push: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Tag | |
run: | | |
CLEAN_TAG=$(echo "${{ github.event.pull_request.head.ref }}" | tr / -) | |
echo "TAG=$CLEAN_TAG" >> $GITHUB_ENV | |
- name: Build | |
run: | | |
docker build -t onsdigital/eq-questionnaire-validator:$TAG . | |
docker build -f Dockerfile-ajv -t onsdigital/eq-questionnaire-validator:$TAG-ajv . | |
- name: Push | |
run: | | |
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin | |
echo "Pushing with tag [$TAG]" | |
docker push onsdigital/eq-questionnaire-validator:$TAG | |
echo "Pushing with tag [$TAG-ajv]" | |
docker push onsdigital/eq-questionnaire-validator:$TAG-ajv |