Skip to content

Add GitHub Actions workflow for Cookiecutter #36

Add GitHub Actions workflow for Cookiecutter

Add GitHub Actions workflow for Cookiecutter #36

Workflow file for this run

---
name: Build
on:
pull_request: {}
push:
branches:
- master
jobs:
commitlint:
name: Commit Lint
runs-on: ubuntu-22.04
steps:
- name: Check out the codebase
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 21
- name: Install Node modules
run: npm install
- name: Check program versions
run: |
node --version
npm --version
npm run commitlint -- --version
- name: Validate last commit
if: github.event_name == 'push'
run: npm run commitlint -- --from=HEAD~1 --to=HEAD --verbose
- name: Validate commits in pull request
if: github.event_name == 'pull_request'
run: >-
npm run commitlint --
--from=${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }}
--to=${{ github.event.pull_request.head.sha }}
--verbose
createrole:
name: Create role
needs: commitlint
runs-on: ubuntu-22.04
steps:
- name: Check out the codebase
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install Cookiecutter
run: pip install cookiecutter
- name: Fill in template values
run: |
sudo apt install --yes jq
jq '.namespace |= "acme"' cookiecutter.json > namespace.json
jq '.role_name |= "widgets_service_installer"' namespace.json > widgets_service_installer.json
jq '.description |= "Installs web service"' widgets_service_installer.json > description.json
jq '.author |= "John Doe"' description.json > author.json
jq '.author_website |= "https://www.example.com"' author.json > author_website.json
cat author_website.json
rm cookiecutter.json
mv author_website.json cookiecutter.json
rm namespace.json widgets_service_installer.json description.json author.json
- name: Create role
run: |
cd ..
pwd
ls
cookiecutter cookiecutter-ansible-role --no-input
ls
sudo apt install --yes tree
tree -L 2 widgets_service_installer
cat widgets_service_installer/meta/main.yml
mv widgets_service_installer cookiecutter-ansible-role
- name: Upload role artifact
uses: actions/upload-artifact@v4
with:
name: ansible-role-widgets_service_installer
path: widgets_service_installer
retention-days: 1
yamllint:
name: YAML Lint
needs: createrole
runs-on: ubuntu-22.04
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ansible-role-widgets_service_installer
path: ansible-role-widgets_service_installer
- name: Set up Python 3
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install test dependencies
run: |
cd ansible-role-widgets_service_installer
pip3 install --requirement requirements.txt
- name: Lint code
run: |
cd ansible-role-widgets_service_installer
yamllint .
ansible-lint:
name: Ansible Lint
needs: yamllint
runs-on: ubuntu-22.04
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ansible-role-widgets_service_installer
path: ansible-role-widgets_service_installer
- name: Set up Python 3
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install test dependencies
run: |
cd ansible-role-widgets_service_installer
pip3 install --requirement requirements.txt
- name: Lint code
run: |
cd ansible-role-widgets_service_installer
ansible-lint .
molecule:
name: Molecule
needs: ansible-lint
runs-on: ubuntu-22.04
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ansible-role-widgets_service_installer
path: ansible-role-widgets_service_installer
- name: Set up Python 3.
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install test dependencies
run: pip3 install --requirement requirements.txt
- name: Run Molecule tests
run: |
cd ansible-role-widgets_service_installer
molecule test