-
Notifications
You must be signed in to change notification settings - Fork 5
71 lines (57 loc) · 2.55 KB
/
push_docker_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
# this jobs compares ./devcontainer/dodona-tested.dockerfile with the dockerfile in the repository dodona-edu/docker-images
# if they are different, a pull request is created in the dodona-edu/docker-images repository
name: Create pr for docker image
on:
push:
pull_request:
types:
- closed
branches:
- main
jobs:
pr:
# if: github.event.pull_request.merged == true
name: Create pr for docker image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Send pull-request
env:
PR_NUMBER: ${{ github.event.number }}
REPOSITORY: dodona-edu/docker-images
TOKEN: ${{ secrets.PUSH_TO_DOCKER_IMAGES_ACCESS_TOKEN }}
run: |
FOLDER="$REPOSITORY"
BRANCH_NAME="update-dodona-tested-$PR_NUMBER"
# Store the PAT in a file that can be accessed by the
# GitHub CLI.
echo "$TOKEN" > token.txt
# Authorize GitHub CLI for the current repository
gh auth login --with-token < token.txt
gh repo clone $REPOSITORY $FOLDER -- --depth=1
cd $FOLDER
# Setup the committers identity.
gh auth setup-git
# Create a new feature branch for the changes.
git checkout -b $BRANCH_NAME
# Update the dockerfile to the latest version
cp ../.devcontainer/dodona-tested.dockerfile .
# Add header to the dockerfile to make it clear that it is autogenerated
sed -i '1s/^/# This file is autogenerated by the dodona-edu/universal-judge repository\n # Any changes will be overwritten by the CI\n\n/' dodona-tested.dockerfile
# check git status if the dockerfile has changed
# if not, exit
if [ -z "$(git status --porcelain)" ]; then
echo "No changes to the dockerfile"
exit 0
fi
# Commit the changes and push the feature branch to origin
git commit -am "Chore: update dodona-tested dockerfile"
git push origin $BRANCH_NAME
# Create a pull request in the remote repository
gh pr create \
--body "" \
--title "Update dodona-tested dockerfile to match pr #$PR_NUMBER" \
--body "This pr updates the dodona-tested dockerfile to match pr https://github.com/dodona-edu/universal-judge/pull/$PR_NUMBER" \
--head "$BRANCH_NAME" \
--base "master"