-
Notifications
You must be signed in to change notification settings - Fork 388
Update storing-artifacts.md #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -182,7 +182,117 @@ It seems like we have some linting errors in our code. As this is not a python/b | |||||||||||||||
|
||||||||||||||||
Push that up to your repository and see that the linting now passes, even though we have errors in our code. | ||||||||||||||||
|
||||||||||||||||
Congratulations! You have now created a workflow with multiple jobs, and used artifacts to share data between them. | ||||||||||||||||
Congratulations! 🎉 You have now created a workflow with multiple jobs, and used artifacts to share data between them. | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
## Extra Exercise: Reorganizing Your Workflow | ||||||||||||||||
|
||||||||||||||||
However, while the current setup is a great start for understanding artifacts, but we can make it more efficient and align it with best practices. | ||||||||||||||||
|
||||||||||||||||
We'll modify the workflow to: | ||||||||||||||||
|
||||||||||||||||
- Separate build and test into their own dedicated jobs. | ||||||||||||||||
|
||||||||||||||||
- Have the linting job check out the code directly so it can run in parallel, speeding things up. 🚀 | ||||||||||||||||
|
||||||||||||||||
- Make the build job upload only the necessary build artifact, not the entire source code. | ||||||||||||||||
|
||||||||||||||||
The goal is to transform your current two-job workflow into a more efficient three-job structure: `build`, `test`, and `lint`. | ||||||||||||||||
|
||||||||||||||||
### Tasks | ||||||||||||||||
|
||||||||||||||||
Modify your current workflow to only build the application and upload the resulting build artifact. | ||||||||||||||||
|
||||||||||||||||
- Remove the `Test` step. | ||||||||||||||||
|
||||||||||||||||
- Change the `Upload repo` step to `Upload build artifact`. | ||||||||||||||||
|
||||||||||||||||
<details> | ||||||||||||||||
<summary>complete solution</summary> | ||||||||||||||||
|
||||||||||||||||
```YAML | ||||||||||||||||
Build: | ||||||||||||||||
name: Build | ||||||||||||||||
runs-on: ubuntu-latest | ||||||||||||||||
container: gradle:6-jdk11 | ||||||||||||||||
steps: | ||||||||||||||||
- name: Clone repository | ||||||||||||||||
uses: actions/checkout@v4 | ||||||||||||||||
|
||||||||||||||||
- name: Build application | ||||||||||||||||
run: ci/build-app.sh | ||||||||||||||||
|
||||||||||||||||
- name: Upload build artifact | ||||||||||||||||
uses: actions/upload-artifact@v4 | ||||||||||||||||
with: | ||||||||||||||||
name: code | ||||||||||||||||
path: . | ||||||||||||||||
include-hidden-files: true | ||||||||||||||||
Comment on lines
+225
to
+230
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The exercise step says:
But we're still uploading the full code. Should this upload the |
||||||||||||||||
``` | ||||||||||||||||
|
||||||||||||||||
</details> | ||||||||||||||||
|
||||||||||||||||
Now, create a completely new job for testing. This job will run after the `Build` job is finished and will test the artifact that was created. | ||||||||||||||||
|
||||||||||||||||
Add a new job named `Test`. | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
Make it dependent on the build job using `needs: Build`. | ||||||||||||||||
|
||||||||||||||||
Add a step to `Download build artifact` created by the `Build` job. | ||||||||||||||||
|
||||||||||||||||
Add the `Run unit tests` step that we removed from the original `Build` job. | ||||||||||||||||
|
||||||||||||||||
Your new `Test` job should look like this: | ||||||||||||||||
|
||||||||||||||||
```YAML | ||||||||||||||||
Test: | ||||||||||||||||
name: Test | ||||||||||||||||
runs-on: ubuntu-latest | ||||||||||||||||
container: gradle:6-jdk11 | ||||||||||||||||
needs: Build | ||||||||||||||||
steps: | ||||||||||||||||
- name: Download build artifact | ||||||||||||||||
uses: actions/download-artifact@v4 | ||||||||||||||||
with: | ||||||||||||||||
name: code | ||||||||||||||||
path: . | ||||||||||||||||
include-hidden-files: true | ||||||||||||||||
Comment on lines
+256
to
+259
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
- name: Run unit tests | ||||||||||||||||
run: ci/unit-test-app.sh | ||||||||||||||||
Comment on lines
+260
to
+262
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File permissions are not preserved when uploaded. The script will have to be made executable in order to run. This needs to be reflected in the exercise steps as well.
Suggested change
|
||||||||||||||||
``` | ||||||||||||||||
|
||||||||||||||||
Finally, let's fix the `Linting` job. Linting only needs the source code; it doesn't depend on the build at all. We can make it run in parallel to save time. | ||||||||||||||||
|
||||||||||||||||
Remove the `needs: [Build]` line. This is the most important change, as it allows the job to start at the same time as build. | ||||||||||||||||
|
||||||||||||||||
Replace the `Download code` step with a `Clone repository` step using `actions/checkout@v4`. | ||||||||||||||||
|
||||||||||||||||
Your lint job should now be much cleaner. | ||||||||||||||||
|
||||||||||||||||
<details> | ||||||||||||||||
<summary>complete solution</summary> | ||||||||||||||||
|
||||||||||||||||
```YAML | ||||||||||||||||
Linting: | ||||||||||||||||
name: Lint | ||||||||||||||||
runs-on: ubuntu-latest | ||||||||||||||||
steps: | ||||||||||||||||
- name: Clone repository | ||||||||||||||||
uses: actions/checkout@v4 | ||||||||||||||||
|
||||||||||||||||
- name: Run linting | ||||||||||||||||
uses: super-linter/super-linter/slim@v7 | ||||||||||||||||
env: | ||||||||||||||||
DEFAULT_BRANCH: main | ||||||||||||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||||||||||||
DISABLE_ERRORS: true | ||||||||||||||||
``` | ||||||||||||||||
|
||||||||||||||||
</details> | ||||||||||||||||
|
||||||||||||||||
Congratulations! 🎉 Push the updated workflow file to your repository. You now have an efficient and easy-to-understand CI/CD pipeline. ⭐ | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
### Resources | ||||||||||||||||
|
||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.