Skip to content

initial-image-build-workflow #66

initial-image-build-workflow

initial-image-build-workflow #66

Workflow file for this run

name: "initial-image-build-workflow"
on:
# Trigger a specific workflow run on demand without need for a code push/pull request
workflow_dispatch:
inputs:
githubRepo:
description: "Link of public github repo to deploy"
required: true
jobs:
create_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}/${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]
git submodule add ${{ github.event.inputs.githubRepo }} ./submissions-${year}/${user_name}-${repo_name}/${user_name}-${repo_name}
git commit -m "Added ${user_name}-${repo_name} as a submodule by github-actions"
git push
else
echo "Submodule already exists, terminating github actions"
fi
outputs:
status: ${{ steps.create_student_submodule.outcome }}
year: ${{ env.YEAR }}
user_name: ${{ env.USER_NAME }}
repo_name: ${{ env.REPO_NAME }}
create_docker_image:
needs: create_submodule
permissions:
contents: "write"
runs-on: ubuntu-latest
defaults:
run:
shell: bash
if: needs.create_submodule.outputs.status == 'success'
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install it depends to deduce dependencies.
run: pip install it-depends
- name: Pull the changes made in the repository.
run: git pull --recurse-submodules
- name: Get submodule's dependencies in JSON file
run: |
cd ./submissions-${{ needs.create_submodule.outputs.year }}/${{ needs.create_submodule.outputs.user_name }}-${{ needs.create_submodule.outputs.repo_name}}/${{ needs.create_submodule.outputs.user_name }}-${{ needs.create_submodule.outputs.repo_name }}
it-depends --depth-limit 1 >> ${{ needs.create_submodule.outputs.user_name }}-${{ needs.create_submodule.outputs.repo_name }}.json
- name: Check if the JSON file was created successfully
run: |
if [[ -f ${{ needs.create_submodule.outputs.user_name }}-${{ needs.create_submodule.outputs.repo_name }}.json ]]; then
cat ${{ needs.create_submodule.outputs.user_name }}-${{ needs.create_submodule.outputs.repo_name }}.json
if [[ -f ${{ needs.create_submodule.outputs.user_name }}-${{ needs.create_submodule.outputs.repo_name }}.json ]]; then
cat ${{ needs.create_submodule.outputs.user_name }}-${{ needs.create_submodule.outputs.repo_name }}.json
else
echo "${{ needs.create_submodule.outputs.user_name }}-${{ needs.create_submodule.outputs.repo_name }}.json does not exist!"
fi
# need to add export DOCKER_BUILDKIT=1 before building python docker image