Feature/add workflow output #36
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: "update-image-build-workflow" | |
on: | |
workflow_dispatch: | |
inputs: | |
githubRepo: | |
description: "Link of public github repo to deploy" | |
required: true | |
outputs: | |
student_url: | |
description: "student's deployment url" | |
value: ${{ jobs.deploy-with-helm.outputs.students_url }} | |
jobs: | |
check_if_update_needed: | |
permissions: | |
contents: "write" | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- id: check_current_state_of_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}/${user_name}-${repo_name} ]; then | |
git config --global user.name github-actions | |
git config --global user.email [email protected] | |
git submodule update --init --recursive | |
cd ./submissions-${year}/${user_name}-${repo_name} | |
SHA_VALUE="$(git submodule status ./${user_name}-${repo_name} | awk '{print $1}')" | |
if [[ ${SHA_VALUE:0:1} == '-' ]]; then | |
SHA_VALUE=${SHA_VALUE:1} | |
fi | |
git submodule update --init --recursive --remote | |
NEW_SHA_VALUE="$(git submodule status ./${user_name}-${repo_name} | awk '{print $1}')" | |
if [[ ${NEW_SHA_VALUE} == ${SHA_VALUE} ]]; then | |
echo "STATUS=$(echo 'failure')" >> $GITHUB_ENV | |
echo "No update is needed, skipping the rest of jobs." | |
else | |
echo "STATUS=$(echo 'success')" >> $GITHUB_ENV | |
git add . | |
git commit -m "Updated ${user_name}-${repo_name} submodule by github-actions" | |
git push | |
echo "Pushed the updated submodule to the repository." | |
fi | |
else | |
echo "Submodule does not exist, terminating update-image github actions, please use create-image.yml" | |
echo "STATUS=$(echo 'failure')" >> $GITHUB_ENV | |
fi | |
outputs: | |
status: ${{ steps.check_current_state_of_submodule.outputs.STATUS }} | |
year: ${{ steps.check_current_state_of_submodule.outputs.year}} | |
user_name: ${{ steps.check_current_state_of_submodule.outputs.user_name }} | |
repo_name: ${{ steps.check_current_state_of_submodule.outputs.repo_name }} | |
dockerise-image: | |
uses: ./.github/workflows/dockerise-image.yml | |
needs: check_if_update_needed | |
with: | |
user_name: ${{ needs.check_if_update_needed.outputs.user_name }} | |
repo_name: ${{ needs.check_if_update_needed.outputs.repo_name }} | |
year: ${{ needs.check_if_update_needed.outputs.year }} | |
submodule_status: ${{ needs.check_if_update_needed.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 }} | |
get_students_url: | |
runs-on: ubuntu-latest | |
needs: trigger_deployment | |
steps: | |
- name: echo_success | |
runs: echo "Successfully retrieved repo_url ${{ needs.trigger_deployment.outputs.student_url }}" | |
outputs: | |
student_url: ${{ needs.trigger_deployment.outputs.student_url }} |