Link videos to existing tutorials. (#53) #96
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: Docker | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| schedule: | |
| # Run every week at 20:00 on Sunday | |
| - cron: "0 20 * * 0" | |
| env: | |
| REGISTRY_IMAGE: ghcr.io/${{ github.repository_owner }}/tutorials | |
| RAW_BRANCH_NAME: ${{ github.head_ref || github.ref_name }} | |
| jobs: | |
| build: | |
| name: Build and push image | |
| strategy: | |
| fail-fast: false | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: true | |
| - name: Pull latest image for caching | |
| run: | | |
| docker pull ${{ env.REGISTRY_IMAGE }}:latest | |
| continue-on-error: true | |
| - name: Also pull this branch's image for caching | |
| run: | | |
| export BRANCH_NAME=$(echo ${{ env.RAW_BRANCH_NAME }} | sed 's/\//-/g') | |
| docker pull ${{ env.REGISTRY_IMAGE }}:$BRANCH_NAME | |
| continue-on-error: true | |
| - name: Build Docker image | |
| run: | | |
| docker compose build | |
| - name: Test Docker image | |
| run: | | |
| docker compose run base colcon test --packages-select tutorial_run --event-handlers console_cohesion+ --return-code-on-test-failure --retest-until-pass 5 | |
| - name: Push to gh registry with sha and branch | |
| # Do not push on PRs from forks. | |
| if: ${{ !github.event.pull_request.head.repo.fork }} | |
| run: | | |
| echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin | |
| # tag with sha and push | |
| docker tag ${{ env.REGISTRY_IMAGE }}:latest ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} | |
| docker push ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} | |
| # tag with branch name and push | |
| export BRANCH_NAME=$(echo ${{ env.RAW_BRANCH_NAME }} | sed 's/\//-/g') | |
| docker tag ${{ env.REGISTRY_IMAGE }}:latest ${{ env.REGISTRY_IMAGE }}:$BRANCH_NAME | |
| docker push ${{ env.REGISTRY_IMAGE }}:$BRANCH_NAME | |
| echo "TAG_NAME=$BRANCH_NAME" >> $GITHUB_ENV | |
| - name: Push to gh registry with latest if this is main | |
| run: | | |
| echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin | |
| # only from main we actually push to latest | |
| docker push ${{ env.REGISTRY_IMAGE }}:latest | |
| echo "TAG_NAME=latest" >> $GITHUB_ENV | |
| if: github.ref == 'refs/heads/main' |