Skip to content

Commit 24460cf

Browse files
committed
Task A-5: Added reusable workflow
Storing a reusable workflow in the e-mission-server repo. Can decide where to place it in a central location. https://docs.github.com/en/actions/sharing-automations/reusing-workflows It essentially works like a function call in normal programming. The advantage is that we have no repeated code the image build process. All the other repos (join, admin-dash, public-dash) reuse the same workflow file. Additionally, on for future GitHub actions, workflow file related changes, will no longer need to have 3 additional PRs for each repo (join, admin-dash, public-dash). Can simply modify the reusable workflow file as this is the core “function” workflow that is being called. I have added conditional checks that check for the repo name in the reusable workflow file that determine which statements to execute depending on for which repo the workflow is running. This is used for both push events specific to a repo as well as for the workflow dispatch events triggered on pushes to server repo.
1 parent acb9f3a commit 24460cf

File tree

1 file changed

+7
-55
lines changed

1 file changed

+7
-55
lines changed

.github/workflows/image_build_push.yml

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,11 @@ on:
44
push:
55
branches: [ main ]
66

7-
env:
8-
DOCKER_USER: ${{secrets.DOCKER_USER}}
9-
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
10-
117
jobs:
12-
13-
build:
14-
15-
runs-on: ubuntu-latest
16-
17-
steps:
18-
19-
- uses: actions/checkout@v2
20-
21-
- name: Set docker image tags
22-
id: set-tags
23-
run: |
24-
set -a; source .env; set +a
25-
echo "JOIN_IMAGE_TAG=${JOIN_IMAGE_TAG}" >> "$GITHUB_OUTPUT"
26-
echo "Current join-page image tag (push): ${JOIN_IMAGE_TAG}"
27-
28-
- name: docker login
29-
run: | # log into docker hub account
30-
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
31-
32-
- name: Get current date # get the date of the build
33-
id: date
34-
run: echo "date=$(date +'%Y-%m-%d--%M-%S')" >> "$GITHUB_OUTPUT"
35-
36-
- name: Run a one-line script
37-
run: echo running in repo ${GITHUB_REPOSITORY#*/} branch ${GITHUB_REF##*/} on ${{ steps.date.outputs.date }}
38-
39-
- name: build docker image
40-
run: |
41-
docker build -t $DOCKER_USER/${GITHUB_REPOSITORY#*/}:${GITHUB_REF##*/}_${{ steps.date.outputs.date }} ./frontend
42-
docker images
43-
44-
- name: push docker image
45-
run: |
46-
docker push $DOCKER_USER/${GITHUB_REPOSITORY#*/}:${GITHUB_REF##*/}_${{ steps.date.outputs.date }}
47-
48-
- name: Update .env file
49-
run: |
50-
echo "JOIN_IMAGE_TAG=${GITHUB_REF##*/}_${{ steps.date.outputs.date }}" > .env
51-
52-
- name: Add, Commit, Push changes to .env file
53-
run: |
54-
git config --local user.email "[email protected]"
55-
git config --local user.name "Github Actions bot to update .env with latest tags"
56-
if git diff --quiet; then
57-
echo "Latest timestamp already present in .env file, no changes to commit"
58-
else
59-
git add .env
60-
git commit -m "Updated docker image tags in .env file to the latest timestamp"
61-
git push origin
62-
fi
8+
build:
9+
if: ${{ !contains(github.event.head_commit.author.name, 'Github Actions bot to update .env with latest tags') }}
10+
uses: e-mission/e-mission-server/.github/workflows/reusable_image_build_push.yml@master
11+
with:
12+
repo: ${{ github.event.repository.name }}
13+
branch: ${{ github.ref_name }}
14+
secrets: inherit

0 commit comments

Comments
 (0)