Skip to content

Merge pull request #160 from CodingBlackFemales/develop #327

Merge pull request #160 from CodingBlackFemales/develop

Merge pull request #160 from CodingBlackFemales/develop #327

Workflow file for this run

# This workflow deploys the CBF WordPress application on a successful push or PR
name: CI
# Controls when the action will run. Triggers the workflow on push or pull request events
on:
push:
branches: [ develop, main ]
pull_request:
branches: [ develop, main ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
setup:
if: ${{ !contains(github.event.head_commit.message, 'chore(release)') }}
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- name: Cache Composer dependencies
uses: actions/cache@v3
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Install dependencies
uses: php-actions/composer@v6
with:
php_version: 8.1
- name: Install phpcs
run: vendor/bin/phpcs -i
- name: PHP Code Style (phpcs)
run: composer lint:all
version:
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' && !contains(github.event.head_commit.author.name, 'GitHub Action') }}
needs: [ setup ]
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Map a step output to a job output
outputs:
executed: ${{ steps.tag_release.outputs.executed }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout repo
uses: actions/checkout@v3
with:
token: ${{ secrets.ADMIN_GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
# Bumps version, updates changelog and creates tag. Adds [skip ci] to commit message to prevent infinite workflow loop
- name: Tag release
id: tag_release
run: |
git fetch --unshallow --tags
git config --global user.email "${{github.event.pusher.email}}"
git config --global user.name "${{github.event.pusher.name}}"
npx --yes commit-and-tag-version
message=`git log -1 --pretty=format:%B | cat`
git commit --amend -m "$message
[skip ci]"
tag=$(git describe --tags $(git rev-list --tags --max-count=1))
git tag -f $tag
git push --atomic --no-verify origin main $tag
echo 'executed=true' >> $GITHUB_OUTPUT
deploy:
# Ensure execution for stage deployments, as dependent version job is skipped
if: ${{ github.event_name == 'push' && !failure() && (success() || !needs.version.outputs.executed) }}
needs: [ setup, version ]
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Triggers release generation
- name: Deploy to hosting environment
env:
WORKFLOW_ID: ${{ 'deploy-application.yml' }}
uses: actions/github-script@v6
with:
script: |-
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: '${{ env.WORKFLOW_ID }}',
ref: '${{ github.ref }}',
inputs: {
destinationEnvironment: '${{github.ref}}' === 'refs/heads/main' ? 'production' : 'staging',
sourceBranch: '${{ github.ref }}',
},
})
.catch(error => error)
.then(response => {
core.debug(response);
if (response.status !== 204) {
core.setFailed(`createWorkflowDispatch to ${{ env.WORKFLOW_ID }} received status code ${response.status}`)
}
})