Skip to content

Update README.md - testing #35

Update README.md - testing

Update README.md - testing #35

name: "CI/CD pull request"
# The total recommended execution time for the "CI/CD Pull Request" workflow is around 20 minutes.
on:
push:
branches:
- "**"
pull_request:
types: [opened, reopened, closed]
jobs:
metadata:
runs-on: ubuntu-latest
timeout-minutes: 1
outputs:
build_datetime_london: ${{ steps.variables.outputs.build_datetime_london }}
build_datetime: ${{ steps.variables.outputs.build_datetime }}
build_timestamp: ${{ steps.variables.outputs.build_timestamp }}
build_epoch: ${{ steps.variables.outputs.build_epoch }}
does_pull_request_exist: ${{ steps.pr_exists.outputs.does_pull_request_exist }}
steps:
- name: "Checkout code"
uses: actions/checkout@v4
- name: "Set CI/CD variables"
id: variables
run: |
datetime=$(date -u +'%Y-%m-%dT%H:%M:%S%z')
echo "build_datetime_london=$(TZ=Europe/London date --date=$datetime +'%Y-%m-%dT%H:%M:%S%z')" >> $GITHUB_OUTPUT
echo "build_datetime=$datetime" >> $GITHUB_OUTPUT
echo "build_timestamp=$(date --date=$datetime -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
echo "build_epoch=$(date --date=$datetime -u +'%s')" >> $GITHUB_OUTPUT
- name: "Check if pull request exists for this branch"
id: pr_exists
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
branch_name=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')}
echo "Current branch is '$branch_name'"
if gh pr list --head $branch_name | grep -q .; then
echo "Pull request exists"
echo "does_pull_request_exist=true" >> $GITHUB_OUTPUT
else
echo "Pull request doesn't exist"
echo "does_pull_request_exist=false" >> $GITHUB_OUTPUT
fi
- name: "List variables"
run: |
export BUILD_DATETIME_LONDON="${{ steps.variables.outputs.build_datetime_london }}"
export BUILD_DATETIME="${{ steps.variables.outputs.build_datetime }}"
export BUILD_TIMESTAMP="${{ steps.variables.outputs.build_timestamp }}"
export BUILD_EPOCH="${{ steps.variables.outputs.build_epoch }}"
export DOES_PULL_REQUEST_EXIST="${{ steps.pr_exists.outputs.does_pull_request_exist }}"
make list-variables
commit-stage: # Recommended maximum execution time is 2 minutes
needs: [metadata]
uses: ./.github/workflows/stage-1-commit.yaml
with:
build_datetime: "${{ needs.metadata.outputs.build_datetime }}"
build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}"
build_epoch: "${{ needs.metadata.outputs.build_epoch }}"
secrets: inherit
test-stage: # Recommended maximum execution time is 5 minutes
needs: [metadata, commit-stage]
uses: ./.github/workflows/stage-2-test.yaml
with:
build_datetime: "${{ needs.metadata.outputs.build_datetime }}"
build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}"
build_epoch: "${{ needs.metadata.outputs.build_epoch }}"
secrets: inherit
build-stage: # Recommended maximum execution time is 3 minutes
needs: [metadata, test-stage]
uses: ./.github/workflows/stage-3-build.yaml
if: needs.metadata.outputs.does_pull_request_exist == 'true' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'closed'))
with:
build_datetime: "${{ needs.metadata.outputs.build_datetime }}"
build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}"
build_epoch: "${{ needs.metadata.outputs.build_epoch }}"
secrets: inherit
acceptance-stage: # Recommended maximum execution time is 10 minutes
needs: [metadata, build-stage]
uses: ./.github/workflows/stage-4-acceptance.yaml
if: needs.metadata.outputs.does_pull_request_exist == 'true' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'closed'))
with:
build_datetime: "${{ needs.metadata.outputs.build_datetime }}"
build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}"
build_epoch: "${{ needs.metadata.outputs.build_epoch }}"
secrets: inherit
publish:
runs-on: ubuntu-latest
needs: [metadata, acceptance-stage]
### if: github.event.pull_request.merged == 'true'
steps:
- name: "Trigger the publish workflow"
run: |
curl -X POST \
-H "Authorization: token ${{secrets.GITHUB_TOKEN}}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$(echo ${{ github.repository }} | cut -d '/' -f 1)/$(echo ${{ github.repository }} | cut -d '/' -f 2)/dispatches \
-d '{"event_type":"trigger-publish-workflow"}'