This repository has been archived by the owner on Oct 29, 2024. It is now read-only.
2b. Example CI/CD deploy from specific repo #1
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: "2b. CI/CD deploy from specific repo" | |
on: | |
workflow_dispatch: | |
# inputs: | |
# release: | |
# type: choice | |
# description: "Sets as an actual non pre release and removes semantic trailing" | |
# default: 'false' | |
# options: | |
# - 'true' | |
# - 'false' | |
#tag: | |
# description: "This is the tag that is oging to be deployed" | |
# required: true | |
# default: "latest" | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
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 }} | |
version: ${{ steps.variables.outputs.version }} | |
# tag: ${{ steps.variables.outputs.tag }} | |
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 | |
# TODO: Get the version, but it may not be the .version file as this should come from the CI/CD Pull Request Workflow | |
echo "version=$(head -n 1 .version 2> /dev/null || echo unknown)" >> $GITHUB_OUTPUT | |
# echo "tag=${{ github.event.inputs.tag }}" >> $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 }}" | |
export VERSION="${{ steps.variables.outputs.version }}" | |
# export TAG="${{ steps.variables.outputs.tag }}" | |
make list-variables | |
deploy-jekyll: | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
needs: metadata | |
steps: | |
- name: "Checkout code" | |
uses: actions/checkout@v4 | |
- name: "Get asset" | |
id: get-asset | |
shell: bash | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
json=$(gh release list --json tagName --limit 1 --repo github.com/NHSDigital/rossbugginsnhs-nhs-notify-repository-template) | |
echo $json | |
tag=$(echo $json | (jq -r '.[0].tagName')) | |
echo $tag | |
gh release download $tag -p jekyll-docs-*.tar --output artifact.tar --repo github.com/NHSDigital/rossbugginsnhs-nhs-notify-repository-template | |
ls -la | |
echo tag=$(echo $tag) >> $GITHUB_OUTPUT | |
- uses: actions/upload-artifact@v4 | |
with: | |
# Name of the artifact to upload. | |
# Optional. Default is 'artifact' | |
name: jekyll-docs-${{steps.get-asset.outputs.tag}} | |
# A file, directory or wildcard pattern that describes what to upload | |
# Required. | |
path: artifact.tar | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
with: | |
artifact_name: jekyll-docs-${{steps.get-asset.outputs.tag}} |