Skip to content

initial-image-build-workflow #365

initial-image-build-workflow

initial-image-build-workflow #365

Workflow file for this run

name: "initial-image-build-workflow"
on:
workflow_dispatch:
inputs:
githubRepo:
description: "Link of public github repo to deploy"
required: true
email:
description: "Email address to send email to"
required: true
jobs:
create_student_submodule:
permissions:
contents: "write"
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
- id: create_student_submodule
name: Add student's repo as a submodule
run: |
year=$(date '+%Y')
initial_user_name=$(echo "${{ github.event.inputs.githubRepo }}" | cut -d'/' -f4)
initial_repo_name=$(echo "${{ github.event.inputs.githubRepo }}" | cut -d'/' -f5)
user_name_lower_case=$(echo "$initial_user_name" | tr '[:upper:]' '[:lower:]')
repo_name_lower_case=$(echo "$initial_repo_name" | tr '[:upper:]' '[:lower:]')
user_name=$(echo "$user_name_lower_case" | tr '._' '-')
repo_name=$(echo "$repo_name_lower_case" | tr '._' '-')
echo "year=$(date '+%Y')" >> "$GITHUB_OUTPUT"
echo "user_name=$user_name" >> "$GITHUB_OUTPUT"
echo "repo_name=$repo_name" >> "$GITHUB_OUTPUT"
if [ ! -d submissions-${year} ]; then
mkdir submissions-${year}
fi
if [ ! -d submissions-${year}/${user_name}-${repo_name} ]; then
echo "Adding ${{ github.event.inputs.githubRepo }} to ./submissions-${year}/${user_name}-${repo_name}/${user_name}-${repo_name} as a submodule"
git config --global user.name github-actions
git config --global user.email [email protected]
cd ./submissions-${year}
mkdir ${user_name}-${repo_name}
cd ./${user_name}-${repo_name}
git submodule add ${{ github.event.inputs.githubRepo }} ./${user_name}-${repo_name}
git commit -m "Added ${user_name}-${repo_name} as a submodule by github-actions"
git push
echo "STATUS=$(echo 'success')" >> "$GITHUB_OUTPUT"
else
echo "Submodule already exists, terminating github actions"
echo "STATUS=$(echo 'failure')" >> "$GITHUB_OUTPUT"
fi
outputs:
status: ${{ steps.create_student_submodule.outputs.STATUS }}
year: ${{ steps.create_student_submodule.outputs.year}}
user_name: ${{ steps.create_student_submodule.outputs.user_name }}
repo_name: ${{ steps.create_student_submodule.outputs.repo_name }}
dockerise-image:
uses: ./.github/workflows/dockerise-image.yml
needs: create_student_submodule
with:
user_name: ${{ needs.create_student_submodule.outputs.user_name }}
repo_name: ${{ needs.create_student_submodule.outputs.repo_name }}
year: ${{ needs.create_student_submodule.outputs.year }}
submodule_status: ${{ needs.create_student_submodule.outputs.status }}
repo_url: ${{ github.event.inputs.githubRepo }}
secrets:
DEPENDENCY_GRAPH_TOKEN: ${{ secrets.DEPENDENCY_GRAPH_TOKEN }}
trigger_deployment:
uses: ./.github/workflows/deploy-image.yml
needs: dockerise-image
with:
user_name: ${{ needs.dockerise-image.outputs.user_name }}
repo_name: ${{ needs.dockerise-image.outputs.repo_name }}
year: ${{ needs.dockerise-image.outputs.year }}
image: ${{ needs.dockerise-image.outputs.image_name }}
email: ${{ github.event.inputs.email }}