Small improvements #154
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: On Push | |
| on: [push] | |
| jobs: | |
| ImageName: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| image: ${{ steps.image-name.outputs.name }} | |
| tag: ${{ steps.image-name.outputs.tag }} | |
| repo: ${{ steps.image-name.outputs.repo }} | |
| branch: ${{ steps.image-name.outputs.branch }} | |
| steps: | |
| - name: Get Image Name | |
| id: image-name | |
| run: | | |
| REPO_NAME=$(echo "${{ github.event.repository.name }}" | tr '[:upper:]' '[:lower:]') | |
| BRANCH_NAME=$(echo "${{ github.ref_name }}" | tr '[:upper:]' '[:lower:]') | |
| echo "name=ghcr.io/archieatkinson/$REPO_NAME:$BRANCH_NAME" >> "$GITHUB_OUTPUT" | |
| echo "tag=$REPO_NAME:$BRANCH_NAME" >> "$GITHUB_OUTPUT" | |
| echo "repo=$REPO_NAME" >> "$GITHUB_OUTPUT" | |
| echo "branch=$BRANCH_NAME" >> "$GITHUB_OUTPUT" | |
| Docker: | |
| runs-on: ubuntu-latest | |
| needs: [ImageName] | |
| outputs: | |
| image: ${{ steps.image-to-use.outputs.NAME }} | |
| steps: | |
| - name: Check out repository code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: extractions/setup-just@v2 | |
| - name: Get last successful commit | |
| id: last-successful-commit | |
| uses: tylermilner/last-successful-commit-hash-action@v1 | |
| continue-on-error: true | |
| with: | |
| workflow-id: on-push.yml | |
| branch: ${{ github.ref_name }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set final commit hash | |
| id: final-commit | |
| run: | | |
| if [ "${{ steps.last-successful-commit.outcome }}" == "success" ]; then | |
| COMMIT_HASH="${{ steps.last-successful-commit.outputs.commit-hash }}" | |
| else | |
| git fetch origin trunk | |
| COMMIT_HASH=$(git merge-base origin/trunk ${{ github.ref_name }}) | |
| fi | |
| echo "commit-hash=$COMMIT_HASH" >> $GITHUB_OUTPUT | |
| - name: Has dockerfile changed | |
| id: Has-dockerfile-changed | |
| uses: tj-actions/changed-files@v44 | |
| with: | |
| base_sha: ${{ steps.final-commit.outputs.commit-hash }} | |
| files: | | |
| .devcontainer/Dockerfile | |
| west.yml | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{github.actor}} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and Push Docker File | |
| if: steps.Has-dockerfile-changed.outputs.any_changed == 'true' | |
| uses: docker/build-push-action@v3 | |
| with: | |
| context: . | |
| push: true | |
| file: .devcontainer/Dockerfile | |
| tags: ${{needs.ImageName.outputs.image}} | |
| - name: Get Image Tags | |
| id: image-tags | |
| run: | | |
| echo "tags=$(just list_image_tags ghcr.io archieatkinson/${{needs.ImageName.outputs.repo}} ${{ secrets.GITHUB_TOKEN }})" >> "$GITHUB_OUTPUT" | |
| - name: Select New Image | |
| id: image-to-use | |
| run: | | |
| if echo "${{ steps.image-tags.outputs.tags }}" | grep -qi "${{ github.ref_name }}"; then | |
| echo "NAME=${{needs.ImageName.outputs.image}}" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "NAME=ghcr.io/archieatkinson/${{needs.ImageName.outputs.repo}}:trunk" >> "$GITHUB_OUTPUT" | |
| fi | |
| Build: | |
| needs: [Docker, ImageName] | |
| runs-on: ubuntu-latest | |
| container: | |
| image: ${{needs.Docker.outputs.image}} | |
| credentials: | |
| username: ${{github.actor}} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| defaults: | |
| run: | |
| working-directory: /home/user/west-workspace/notus | |
| steps: | |
| - name: Check out repository code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Env | |
| run: | | |
| mv $GITHUB_WORKSPACE/* /home/user/west-workspace/notus | |
| mv $GITHUB_WORKSPACE/.[!.]* /home/user/west-workspace/notus | |
| chmod 777 -R /home/user/west-workspace/notus | |
| echo "ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-$ZSDK_VERSION" >> $GITHUB_ENV | |
| git config --global --add safe.directory "*" | |
| west update | |
| - name: Build | |
| run: just test | |
| - name: Upload | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: twister_out | |
| path: /home/user/west-workspace/notus/twister-out/ |