Please begin by reading the following subsections, Experiment n (where n ranges from 1 to 4). You then return to this section to complete the codebase setup for each section.
1. Go to your GitHub organization created in 4.1 Create AWSome Books Repository.
2. Fill out the following information.
fcj-workshops-2024
.experiment-n
where n is the experimental subsection you are working on.3. Scroll down to the botttom. Click Create repository.
4. Choose your favorite workspace on your local machine. Clone this remote repository github.com/Definitely-not-AWS-Workshops/get-1s.
git clone https://github.com/Definitely-not-AWS-Workshops/get-1s
Along with the unchanged content of main.py and test.py from the previous section, let’s now get an overview of the CI workflow defined in .github/workflows/ci.yml.
name: CI
on:
pull_request:
merge_group:
branches: [main]
jobs:
run-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Extend the workflow duration by an additional 10 seconds.
run: sleep 10
- name: Show main.py content
run: cat main.py
- name: Show test.py content
run: cat test.py
- name: Run tests
run: python test.py
In general, this workflow is triggered when a pull request is created or when a branch is part of a merge group (main branch). It sets up a CI job on an Ubuntu machine, checks out the code, installs Python 3.9, prints the contents of two files (main.py and test.py) for troubleshooting, and finally runs the test file (test.py) to validate the code changes. The sleep 10 step appears to add a delay, possibly for debugging purposes.
5. Change the directory name to experiment-n
where n is the experimental subsection you are working on.
mv get-1s experiment-n
6. Change into the directory experiment-n
where n is the experimental subsection you are working on. And then remove the .git folder.
cd experiment-n && rm -rf .git
7. Initialize a new git repository.
git init
8. Link to the remote repository that you have just created with experiment-n
where n is the experimental subsection you are working on
git remote add origin https://github.com/fcj-workshops-2024/experiment-n.git
9. Make your first commit and push to the remote repository.
git add . && git commit -m "first commit" && git push --set-upstream origin main
10. Create and switch to the person-a branch.
git checkout -b person-a
11. In the main.py file, change the default value of the parameter n from DEFAULT
to 7
.
|
|
12. Run the test.
python test.py
It should be successful for your test to run.
13. Make a commit.
git add . && git commit -m "change the default value of the parameter n from DEFAULT to 7"
14. Switch to the main branch.
git checkout main
15. Create and switch to the person-b branch.
git checkout -b person-b
16. Make a change to main.py file.
|
|
17. Add a test to test.py file.
|
|
18. Run the test.
python test.py
It should be successful for your test to run.
19. Make a commit.
git add . && git commit -m "modify the get_1s return and add another test"
Your code changes on each branch have passed all local tests successfully! However, if either person a or person b merges their changes into the main branch first, and on the other branch you then forget to pull the latest updates from main before running your local tests again, you might run into unexpected issues when creating a pull request and merging back to main.
To investigate, you run a series of experiments to see if your well-tested local code changes could still fail during pull requests, even when there are no visible code conflicts.