CI/CD publish #40
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: "CI/CD publish" | |
on: | |
workflow_run: | |
workflows: ["CI/CD pull request"] | |
branches: [ "main" ] | |
types: ["completed"] | |
jobs: | |
metadata: | |
name: "Set CI/CD metadata" | |
runs-on: ubuntu-latest | |
timeout-minutes: 1 | |
outputs: | |
build_datetime: ${{ steps.variables.outputs.build_datetime }} | |
build_timestamp: ${{ steps.variables.outputs.build_timestamp }} | |
build_epoch: ${{ steps.variables.outputs.build_epoch }} | |
nodejs_version: ${{ steps.variables.outputs.nodejs_version }} | |
python_version: ${{ steps.variables.outputs.python_version }} | |
terraform_version: ${{ steps.variables.outputs.terraform_version }} | |
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=$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 | |
echo "nodejs_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT | |
echo "python_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT | |
echo "terraform_version=$(grep "^terraform" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT | |
- name: "List variables" | |
run: | | |
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 NODEJS_VERSION="${{ steps.variables.outputs.nodejs_version }}" | |
export PYTHON_VERSION="${{ steps.variables.outputs.python_version }}" | |
export TERRAFORM_VERSION="${{ steps.variables.outputs.terraform_version }}" | |
make list-variables | |
publish: | |
name: "Publish packages" | |
runs-on: ubuntu-latest | |
needs: [metadata] | |
timeout-minutes: 3 | |
outputs: | |
version: ${{ steps.semantic.outputs.new_release_version }} | |
steps: | |
- name: "Checkout code" | |
uses: actions/checkout@v4 | |
- name: "Semantic Release" | |
uses: cycjimmy/[email protected] | |
id: semantic | |
with: | |
dry_run: ${{github.event_name == 'pull_request'}} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: "Output new release details" | |
if: steps.semantic.outputs.new_release_published == 'true' | |
run: | | |
echo ${{ steps.semantic.outputs.new_release_version }} | |
echo ${{ steps.semantic.outputs.new_release_major_version }} | |
echo ${{ steps.semantic.outputs.new_release_minor_version }} | |
echo ${{ steps.semantic.outputs.new_release_patch_version }} | |
export VERSION="${{ steps.semantic.outputs.new_release_version }}" | |
make list-variables | |
success: | |
name: "Success notification" | |
runs-on: ubuntu-latest | |
needs: [publish] | |
steps: | |
- name: "Check prerequisites for notification" | |
id: check | |
run: echo "secret_exist=${{ secrets.TEAMS_NOTIFICATION_WEBHOOK_URL != '' }}" >> $GITHUB_OUTPUT | |
- name: "Notify on publishing packages" | |
if: steps.check.outputs.secret_exist == 'true' | |
uses: nhs-england-tools/notify-msteams-action@main | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
teams-webhook-url: ${{ secrets.TEAMS_NOTIFICATION_WEBHOOK_URL }} | |
message-title: "nhs-england-tools/notify-msteams-action@v${{ needs.metadata.outputs.version }}" | |
message-text: "A new version of this GitHub action has just been published." | |
link: ${{ github.event.pull_request.html_url }} |