diff --git a/.github/scripts/setup.sh b/.github/scripts/setup.sh new file mode 100644 index 00000000..468c9feb --- /dev/null +++ b/.github/scripts/setup.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# shellcheck disable=SC2129 + +main() { + BRANCH_OR_TAG="$(echo "${GITHUB_REF}" | sed 's/refs\/heads\///g' | sed 's/refs\/tags\///g')" + PROJECT_NAME="ansible-workbench" + echo "BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> "$GITHUB_ENV" + echo "WEBHOOK_URL=${WEBHOOK_URL}" >> "$GITHUB_ENV" + echo "PROJECT_NAME=${PROJECT_NAME}" >> "$GITHUB_ENV" + echo "NOTIFICATION=${PROJECT_NAME} [${BRANCH_OR_TAG}]" >> "$GITHUB_ENV" + echo "USERNAME=shared-vision-solutions" >> "$GITHUB_ENV" + echo "TEMPLATED_NAME=flower-generator" >> "$GITHUB_ENV" +} + +main diff --git a/.github/template.sh b/.github/scripts/template.sh similarity index 100% rename from .github/template.sh rename to .github/scripts/template.sh diff --git a/.github/setup.sh b/.github/setup.sh deleted file mode 100644 index 874e78aa..00000000 --- a/.github/setup.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -main() { - BRANCH_OR_TAG="$(echo "${GITHUB_REF}" | sed 's/refs\/heads\///g' | sed 's/refs\/tags\///g')" - PROJECT_NAME="ansible-workbench" - echo "BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> $GITHUB_ENV - echo "WEBHOOK_URL=${WEBHOOK_URL}" >> $GITHUB_ENV - echo "PROJECT_NAME=${PROJECT_NAME}" >> $GITHUB_ENV - echo "NOTIFICATION=${PROJECT_NAME} [${BRANCH_OR_TAG}]" >> $GITHUB_ENV - echo "USERNAME=shared-vision-solutions" >> $GITHUB_ENV -} - -main diff --git a/.github/workflows/self-test.yml b/.github/workflows/self-test.yml index 41b39523..e5f78c44 100644 --- a/.github/workflows/self-test.yml +++ b/.github/workflows/self-test.yml @@ -15,11 +15,11 @@ jobs: documentation_test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: max-parallel: 4 matrix: - python-version: [ 3.7 ] + python-version: [3.7] steps: @@ -28,7 +28,7 @@ jobs: path: 'template' - name: Setup Environment run: | - source ./template/.github/setup.sh + source ./template/.github/scripts/setup.sh env: WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} @@ -38,7 +38,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Create Template run: | - source ./template/.github/template.sh + source ./template/.github/scripts/template.sh - name: Check Markdown Links For Readme uses: gaurav-nelson/github-action-markdown-link-check@1.0.11 @@ -52,20 +52,20 @@ jobs: with: use-quiet-mode: 'no' use-verbose-mode: 'yes' - folder-path: './flower-generator' + folder-path: ${{ env.TEMPLATED_NAME }} max-depth: -1 - name: Report Job Status on Success run: | - ./template/.github/notifications.sh "${NOTIFICATION}" "documentation checks succeeded!" + ./template/{{cookiecutter.project_slug}}/.github/scripts/notifications.sh "${NOTIFICATION}" "documentation checks succeeded!" - name: Report Job Status on Failure if: failure() run: | - ./template/.github/notifications.sh "${NOTIFICATION}" "documentation checks failed!" + ./template/{{cookiecutter.project_slug}}/.github/scripts/notifications.sh "${NOTIFICATION}" "documentation checks failed!" - linting: + molecule_lint_test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: max-parallel: 4 matrix: @@ -78,7 +78,7 @@ jobs: path: 'template' - name: Setup Environment run: | - source ./template/.github/setup.sh + source ./template/.github/scripts/setup.sh env: WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} @@ -88,25 +88,141 @@ jobs: python-version: ${{ matrix.python-version }} - name: Create Template run: | - source ./template/.github/template.sh + source ./template/.github/scripts/template.sh - name: Lint Role Defaults run: | - cd flower-generator + cd ${TEMPLATED_NAME} poetry run molecule lint - name: Report Job Status on Success run: | - ./template/.github/notifications.sh "${NOTIFICATION}" "linting checks succeeded!" + ./template/{{cookiecutter.project_slug}}/.github/scripts/notifications.sh "${NOTIFICATION}" "molecule linting checks succeeded!" - name: Report Job Status on Failure if: failure() run: | - ./template/.github/notifications.sh "${NOTIFICATION}" "linting checks failed!" + ./template/{{cookiecutter.project_slug}}/.github/scripts/notifications.sh "${NOTIFICATION}" "molecule linting checks failed!" + + security_test: + + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: [ 3.7 ] + + steps: + - name: Security Test -- Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + - name: Security Test -- Checkout Repository + uses: actions/checkout@v1 + + - name: Security Test -- Check Dependencies + run: | + pip install safety + pip install --upgrade pip + safety check + + - name: Security Test -- Run Gitleaks + uses: zricethezav/gitleaks-action@master + + - name: Shellcheck -- Report Job Status on Success + run: | + ./{{cookiecutter.project_slug}}/.github/scripts/notifications.sh "${NOTIFICATION}" "security checks succeeded!" + - name: Shellcheck -- Report Job Status on Failure + if: failure() + run: | + ./{{cookiecutter.project_slug}}/.github/scripts/notifications.sh "${NOTIFICATION}" "security checks failed!" + + shellcheck_test: + + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: [3.7] + + steps: + - name: Shellcheck -- Checkout Repository + uses: actions/checkout@v2 + with: + path: 'template' + + - name: Shellcheck -- Setup Environment + run: | + source ./template/.github/scripts/setup.sh + source ./template/.github/scripts/template.sh + env: + WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + + - name: Shellcheck -- Check Template Scripts + run: | + shellcheck ./template/.github/scripts/*.sh + - name: Shellcheck -- Check Rendered Template Scripts + run: | + shellcheck ${TEMPLATED_NAME}/.github/scripts/*.sh + + - name: Shellcheck -- Report Job Status on Success + run: | + ./template/{{cookiecutter.project_slug}}/.github/scripts/notifications.sh "${NOTIFICATION}" "shellcheck checks succeeded!" + - name: Shellcheck -- Report Job Status on Failure + if: failure() + run: | + ./template/{{cookiecutter.project_slug}}/.github/scripts/notifications.sh "${NOTIFICATION}" "shellcheck checks failed!" + + workflow_lint_test: + + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: [3.7] + + steps: + + - name: Workflow Lint -- Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + - name: Workflow Lint -- Checkout Repository + uses: actions/checkout@v2 + with: + path: 'template' + - name: Workflow Lint -- Setup Environment + run: | + source ./template/.github/scripts/setup.sh + env: + WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + + - name: Workflow Lint -- Create Template + run: | + source ./template/.github/scripts/template.sh + + - name: Workflow Lint -- Lint Template Workflows + run: | + yamllint ./template/.github/workflows/*.yml -c ./${TEMPLATED_NAME}/.yamllint + + - name: Workflow Lint -- Lint Role Workflows + run: | + yamllint ./${TEMPLATED_NAME}/.github/workflows/*.yml -c ./${TEMPLATED_NAME}/.yamllint + + - name: Workflow Lint -- Report Job Status on Success + run: | + ./template/{{cookiecutter.project_slug}}/.github/scripts/notifications.sh "${NOTIFICATION}" "workflow linting checks succeeded!" + - name: Workflow Lint -- Report Job Status on Failure + if: failure() + run: | + ./template/{{cookiecutter.project_slug}}/.github/scripts/notifications.sh "${NOTIFICATION}" "workflow linting checks failed!" + push_repository_test: - needs: [linting, documentation_test] + needs: [documentation_test, molecule_lint_test, security_test, shellcheck_test, workflow_lint_test] - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: max-parallel: 4 matrix: @@ -118,77 +234,78 @@ jobs: with: path: 'template' persist-credentials: false - - name: Setup Environment + - name: Push Test -- Setup Environment run: | - source ./template/.github/setup.sh "GitHub Action" "action@github.com" + source ./template/.github/scripts/setup.sh "GitHub Action" "action@github.com" env: WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} - - name: Set up Python ${{ matrix.python-version }} + - name: Push Test -- Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: python-version: ${{ matrix.python-version }} - - name: Create Template + - name: Push Test -- Create Template run: | - source ./template/.github/template.sh + source ./template/.github/scripts/template.sh - - name: Clean Up Tags for Git Push + + - name: Push Test -- Clean Up Tags for Git Push run: | - cd flower-generator + cd ${TEMPLATED_NAME} git checkout master git tag --delete v0.0.0 # Don't Repush git tag v1.0.0 - - name: Push To Test Repository (master) + - name: Push Test -- Push To Test Repository (master) uses: ad-m/github-push-action@v0.6.0 with: github_token: ${{ secrets.REMOTE_TOKEN }} branch: master tags: false - directory: flower-generator + directory: ${{ env.TEMPLATED_NAME }} repository: ${{ secrets.REMOTE_ORIGIN }} force: true - - name: Push To Test Repository (production) + - name: Push Test -- Push To Test Repository (production) uses: ad-m/github-push-action@v0.6.0 with: github_token: ${{ secrets.REMOTE_TOKEN }} branch: production tags: false - directory: flower-generator + directory: ${{ env.TEMPLATED_NAME }} repository: ${{ secrets.REMOTE_ORIGIN }} force: true - - name: Push To Test Repository (release tag) + - name: Push Test -- Push To Test Repository (release tag) uses: ad-m/github-push-action@v0.6.0 with: github_token: ${{ secrets.REMOTE_TOKEN }} branch: production tags: true - directory: flower-generator + directory: ${{ env.TEMPLATED_NAME }} repository: ${{ secrets.REMOTE_ORIGIN }} force: true - - name: Report Job Status on Success + - name: Push Test -- Report Job Status on Success run: | - ./template/.github/notifications.sh "${NOTIFICATION}" "push has been triggered!" + ./template/{{cookiecutter.project_slug}}/.github/scripts/notifications.sh "${NOTIFICATION}" "push has been triggered!" - name: Report Job Status on Failure if: failure() run: | - ./template/.github/notifications.sh "${NOTIFICATION}" "push failed to trigger!" + ./template/{{cookiecutter.project_slug}}/.github/scripts/notifications.sh "${NOTIFICATION}" "push failed to trigger!" create_releases: needs: [push_repository_test] - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: max-parallel: 4 matrix: - python-version: [ 3.7 ] + python-version: [3.7] steps: - uses: actions/checkout@v1 - name: Setup Environment if: contains(github.ref, '/tags/v') run: | - source .github/setup.sh + source .github/scripts/setup.sh env: WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} @@ -215,15 +332,15 @@ jobs: ## Deployment Checklist - [ ] Ensure correct version is notated - [ ] Ensure documentation is accurate - - [ ] Ensure self test passes + - [ ] Ensure git commits are properly formatted draft: true prerelease: false - name: Report Job Status on Success if: contains(github.ref, '/tags/v') run: | - .github/notifications.sh "${NOTIFICATION}" "automated release has been created!" + ./{{cookiecutter.project_slug}}/.github/scripts/notifications.sh "${NOTIFICATION}" "automated release has been created!\nhttps://github.com/${USERNAME}/${PROJECT_NAME}/releases" - name: Report Job Status on Failure if: failure() run: | - .github/notifications.sh "${NOTIFICATION}" "automated release has failed!" + ./{{cookiecutter.project_slug}}/.github/scripts/notifications.sh "${NOTIFICATION}" "automated release has failed!" diff --git a/{{cookiecutter.project_slug}}/.github/markdown/CODE_OF_CONDUCT.md b/{{cookiecutter.project_slug}}/.github/markdown/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..a67ae085 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.github/markdown/CODE_OF_CONDUCT.md @@ -0,0 +1,46 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at {{cookiecutter.email}}. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/{{cookiecutter.project_slug}}/.github/markdown/CONTRIBUTING.md b/{{cookiecutter.project_slug}}/.github/markdown/CONTRIBUTING.md new file mode 100644 index 00000000..35d14406 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.github/markdown/CONTRIBUTING.md @@ -0,0 +1,3 @@ +# Contribution Guide + +[Code of Conduct](./CODE_OF_CONDUCT.md) diff --git a/{{cookiecutter.project_slug}}/.github/markdown/ISSUE_TEMPLATE.md b/{{cookiecutter.project_slug}}/.github/markdown/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..a49528dc --- /dev/null +++ b/{{cookiecutter.project_slug}}/.github/markdown/ISSUE_TEMPLATE.md @@ -0,0 +1,15 @@ +#### What's going wrong? + +#### How can the {{cookiecutter.project_name}} team reproduce the problem? + + + +#### Is this a problem with a fresh install of the project? + +- [ ] Yes +- [ ] No + + diff --git a/{{cookiecutter.project_slug}}/.github/markdown/PULL_REQUEST_TEMPLATE.md b/{{cookiecutter.project_slug}}/.github/markdown/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..ed29480d --- /dev/null +++ b/{{cookiecutter.project_slug}}/.github/markdown/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1 @@ +Closes # for release #. \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/.github/notifications.sh b/{{cookiecutter.project_slug}}/.github/notifications.sh deleted file mode 100755 index ecbecb36..00000000 --- a/{{cookiecutter.project_slug}}/.github/notifications.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -# Takes two text arguments -# Message Format: : - -[[ -z ${WEBHOOK_URL} ]] && exit 0 -curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"${1}: ${2}\"}" "${WEBHOOK_URL}" diff --git a/.github/notifications.sh b/{{cookiecutter.project_slug}}/.github/scripts/notifications.sh similarity index 100% rename from .github/notifications.sh rename to {{cookiecutter.project_slug}}/.github/scripts/notifications.sh diff --git a/{{cookiecutter.project_slug}}/.github/scripts/setup.sh b/{{cookiecutter.project_slug}}/.github/scripts/setup.sh new file mode 100644 index 00000000..33abbc99 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.github/scripts/setup.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# shellcheck disable=SC2129 + +main() { + BRANCH_OR_TAG="$(echo "${GITHUB_REF}" | sed 's/refs\/heads\///g' | sed 's/refs\/tags\///g')" + PROJECT_NAME="{{ cookiecutter.project_slug }}" + echo "BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> "$GITHUB_ENV" + echo "WEBHOOK_URL=${WEBHOOK_URL}" >> "$GITHUB_ENV" + echo "PROJECT_NAME=${PROJECT_NAME}" >> "$GITHUB_ENV" + echo "NOTIFICATION=${PROJECT_NAME} [${BRANCH_OR_TAG}]" >> "$GITHUB_ENV" + echo "USERNAME={{ cookiecutter.github_handle }}" >> "$GITHUB_ENV" +} + +main diff --git a/{{cookiecutter.project_slug}}/.github/workflows/push.yml b/{{cookiecutter.project_slug}}/.github/workflows/push.yml index fbfb344c..7c39a37f 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/push.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/push.yml @@ -1,5 +1,6 @@ -name: {{ cookiecutter.project_slug }}-pushes - +--- +name: {{ cookiecutter.project_slug }}-push +{% raw %} # Workflow Secrets: # SLACK_WEBHOOK (Required, for slack notifications...) @@ -9,75 +10,133 @@ on: jobs: - push: - runs-on: ubuntu-20.04 + build: + + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: [3.7] + + steps: + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + - name: Build -- Checkout Repository + uses: actions/checkout@v1 + + - name: Build -- Setup Environment + run: | + source ./.github/scripts/setup.sh + env: + WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + + - name: Build -- Install Requirements + run: | + pip install poetry + poetry install + - name: Build -- Run Linter + run: | + poetry run molecule lint + - name: Build -- Run docker1 Scenario + run: | + poetry run molecule test -s docker1 + + - name: Build -- Report Job Status (Success) + run: | + ./.github/scripts/notifications.sh "${NOTIFICATION}" "build was successful!" + - name: Build -- Report Job Status (Failure) + if: failure() + run: | + ./.github/scripts/notifications.sh "${NOTIFICATION}" "build has failed!" + + documentation_test: + + runs-on: ubuntu-latest + steps: + - name: Documentation Test -- Checkout Repository + uses: actions/checkout@v1 + - name: Documentation Test -- Documentation Validation + uses: gaurav-nelson/github-action-markdown-link-check@1.0.11 + with: + use-quiet-mode: 'no' + use-verbose-mode: 'yes' + + - name: Documentation Test -- Report Success + run: | + ./.github/scripts/notifications.sh "${NOTIFICATION}" "documentation test has passed!" + - name: Documentation Test -- Report Failure + run: | + ./.github/scripts/notifications.sh "${NOTIFICATION}" "documentation test has failed!" + + security_test: + + runs-on: ubuntu-latest - - name: Setup Environment - run: | - BRANCH_OR_TAG="$(echo "${GITHUB_REF}" | sed 's/refs\/heads\///g' | sed 's/refs\/tags\///g')" - PROJECT_NAME="{{ cookiecutter.project_slug }}" - echo "BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> $GITHUB_ENV - echo "WEBHOOK_URL=${WEBHOOK_URL}" >> $GITHUB_ENV - echo "PROJECT_NAME=${PROJECT_NAME}" >> $GITHUB_ENV - echo "NOTIFICATION=${PROJECT_NAME} [${BRANCH_OR_TAG}]" >> $GITHUB_ENV - echo "USERNAME={{ cookiecutter.github_handle }}" >> $GITHUB_ENV{% raw %} - env: - WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Install Requirements - run: | - pip install poetry - poetry install - - - name: Run Linter - run: | - poetry run molecule lint - - name: Run docker1 Scenario - run: | - poetry run molecule test -s docker1 - - - name: Report Job Status (Success) - run: | - ./.github/notifications.sh "${NOTIFICATION}" "build was successful!" - - name: Report Job Status - if: failure() - run: | - ./.github/notifications.sh "${NOTIFICATION}" "build has failed!" - - - name: Prepare Release Content - if: contains(github.ref, '/tags/v') - run: | - NEWTAG=${BRANCH_OR_TAG} - echo "NEWTAG=${NEWTAG}" >> $GITHUB_ENV - echo "{}" > package.json - - name: Generate Changelog - if: contains(github.ref, '/tags/v') - uses: scottbrenner/generate-changelog-action@1.0.3 - id: Changelog - env: - REPO: ${{ github.repository }} - - name: Create Release - if: contains(github.ref, '/tags/v') - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ env.NEWTAG }} - release_name: Release ${{ env.NEWTAG }} - body: | - ${{ steps.Changelog.outputs.changelog }} - draft: true - prerelease: false - - name: Production -- Report Success - if: contains(github.ref, '/tags/v') - run: | - ./.github/notifications.sh "${NOTIFICATION}" "automated release has been created: https://github.com/${USERNAME}/${PROJECT_NAME}/releases" - - name: Production -- Report Failure - if: failure() && contains(github.ref, '/tags/v') - run: | - ./.github/notifications.sh "${NOTIFICATION}" "automated release generation failed!" + steps: + - name: Security Test -- Checkout Repository + uses: actions/checkout@v1 + - name: Security Test -- Run Gitleaks + uses: zricethezav/gitleaks-action@master + + - name: Security Test -- Report Success + run: | + ./.github/scripts/notifications.sh "${NOTIFICATION}" "security test has passed!" + - name: Security Test -- Report Failure + run: | + ./.github/scripts/notifications.sh "${NOTIFICATION}" "security test has failed!" + + release: + needs: [build, documentation_test, security_test] + + runs-on: ubuntu-latest + + steps: + - name: Release -- Checkout + uses: actions/checkout@v1 + + - name: Release -- Setup Environment + run: | + source ./.github/scripts/setup.sh + env: + WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + + - name: Release -- Prepare Content + if: contains(github.ref, '/tags/v') + run: | + NEWTAG=${BRANCH_OR_TAG} + echo "NEWTAG=${NEWTAG}" >> $GITHUB_ENV + echo "{}" > package.json + - name: Release -- Generate Changelog + if: contains(github.ref, '/tags/v') + uses: scottbrenner/generate-changelog-action@1.0.3 + id: Changelog + env: + REPO: ${{ github.repository }} + - name: Release -- Create Github Release + if: contains(github.ref, '/tags/v') + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.NEWTAG }} + release_name: Release ${{ env.NEWTAG }} + body: | + ${{ steps.Changelog.outputs.changelog }} + draft: true + prerelease: false + + - name: Release -- Report Job Status (Success) + if: contains(github.ref, '/tags/v') + run: | + ./.github/scripts/notifications.sh \ + "${NOTIFICATION}" \ + "automated release has been created: https://github.com/${USERNAME}/${PROJECT_NAME}/releases" + - name: Release -- Report Job Status (Failure) + if: failure() && contains(github.ref, '/tags/v') + run: | + ./.github/scripts/notifications.sh "${NOTIFICATION}" "automated release generation failed!" {% endraw %} \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/.github/workflows/release.yml b/{{cookiecutter.project_slug}}/.github/workflows/release.yml index 542ffa35..7c40487d 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/release.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/release.yml @@ -1,5 +1,6 @@ -name: {{ cookiecutter.project_slug }}-releases - +--- +name: {{ cookiecutter.project_slug }}-publish-to-galaxy +{% raw %} # Workflow Secrets: # SLACK_WEBHOOK (Required, for slack notifications...) # GALAXY_API_KEY (Required, for Ansible Galaxy Import...) @@ -15,47 +16,53 @@ on: default: '' jobs: - release: - runs-on: ubuntu-20.04 + publish_to_galaxy: + + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: [3.7] steps: - - name: Setup Environment - run: | - BRANCH_OR_TAG="$(echo "${GITHUB_REF}" | sed 's/refs\/heads\///g' | sed 's/refs\/tags\///g')" - PROJECT_NAME="{{ cookiecutter.project_slug }}" - echo "BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> $GITHUB_ENV - echo "WEBHOOK_URL=${WEBHOOK_URL}" >> $GITHUB_ENV - echo "PROJECT_NAME=${PROJECT_NAME}" >> $GITHUB_ENV - echo "NOTIFICATION=${PROJECT_NAME} [${BRANCH_OR_TAG}]" >> $GITHUB_ENV - echo "USERNAME={{ cookiecutter.github_handle }}" >> $GITHUB_ENV{% raw %} - env: - WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} - - name: Code Checkout (workflow dispatch) + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + - name: Publish to Galaxy -- Code Checkout (workflow dispatch) if: github.event_name == 'workflow_dispatch' uses: actions/checkout@v2 with: fetch-depth: 0 ref: ${{ github.event.inputs.TAG }} - - name: Code Checkout (published release) + - name: Publish to Galaxy -- Code Checkout (published release) if: github.event_name != 'workflow_dispatch' uses: actions/checkout@v2 with: fetch-depth: 0 - - name: Install Requirements + - name: Publish to Galaxy -- Setup Environment + run: | + source .github/scripts/setup.sh + env: + WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + + - name: Publish to Galaxy -- Install Requirements run: | pip install poetry poetry install - - name: Trigger Ansible Galaxy Import + - name: Publish to Galaxy -- Trigger Ansible Galaxy Import run: | ansible-galaxy role import ${USERNAME} ${PROJECT_NAME} --token ${API_KEY} env: API_KEY: ${{ secrets.GALAXY_API_KEY }} - - name: Production -- Report Success + + - name: Publish to Galaxy -- Report Job Status (Success) run: | - ./.github/notifications.sh "${NOTIFICATION}" "automated galaxy import has been completed!" - - name: Production -- Report Failure + ./.github/scripts/notifications.sh "${NOTIFICATION}" "automated galaxy import has been completed!" + - name: Publish to Galaxy -- Report Job Status (Failure) if: failure() run: | - ./.github/notifications.sh "${NOTIFICATION}" "automated galaxy import has failed!" + ./.github/scripts/notifications.sh "${NOTIFICATION}" "automated galaxy import has failed!" {% endraw %} \ No newline at end of file