-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (79 loc) · 3.51 KB
/
create-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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 }}
secrets:
MAIL_PASSWORD: ${{ secrets.MAIL_PASSWORD }}