Feat/devcontainer (#2) #5
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: Build and Push Devcontainer | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - "*" | |
| workflow_dispatch: | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Checkout the repository | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| # Log in to GitHub Container Registry | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # Determine the Docker tag | |
| - name: Set Docker tag | |
| id: docker-tag | |
| run: | | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| if [[ "${{ github.ref_name }}" == feat/* ]]; then | |
| echo "tag=latest" >> $GITHUB_OUTPUT | |
| else | |
| echo "Manual trigger is not on a feat/* branch. Exiting." | |
| exit 1 | |
| fi | |
| elif [[ "${{ github.ref_type }}" == "tag" ]]; then | |
| echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT | |
| elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | |
| echo "tag=latest" >> $GITHUB_OUTPUT | |
| else | |
| echo "No valid tag condition met. Exiting." | |
| exit 1 | |
| fi | |
| # Build and push the Docker image | |
| - name: Build and push Docker image | |
| run: | | |
| docker build -t ghcr.io/$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]'):${{ steps.docker-tag.outputs.tag }} -f Dockerfile . | |
| docker push ghcr.io/$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]'):${{ steps.docker-tag.outputs.tag }} |