Skip to content

initial-image-build-workflow #330

initial-image-build-workflow

initial-image-build-workflow #330

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
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: |
echo "YEAR=$(date '+%Y')" >> $GITHUB_ENV
echo "USER_NAME=$(echo "${{ github.event.inputs.githubRepo }}" | cut -d'/' -f4)" >> $GITHUB_ENV
echo "REPO_NAME=$(echo "${{ github.event.inputs.githubRepo }}" | cut -d'/' -f5)" >> $GITHUB_ENV
year=$(date '+%Y')
user_name=$(echo "${{ github.event.inputs.githubRepo }}" | cut -d'/' -f4)
repo_name=$(echo "${{ github.event.inputs.githubRepo }}" | cut -d'/' -f5)
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_ENV
else
echo "Submodule already exists, terminating github actions"
echo "STATUS=$(echo 'failure')" >> $GITHUB_ENV
fi
outputs:
status: ${{ env.STATUS }}
year: ${{ env.YEAR }}
user_name: ${{ env.USER_NAME }}
repo_name: ${{ env.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 }}
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 }}
secrets:
KUBE_SERVER_URL: ${{ secrets.KUBE_SERVER_URL }}
KUBE_SERVICE_ACC_SECRET: ${{ secrets.KUBE_SERVICE_ACC_SECRET }}