Merge pull request #8 from HomeDevopsLab:lowercase #7
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: CI/CD | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get version from ChangeLog | |
| id: changelog | |
| run: | | |
| VERSION=$(grep -E '^## \[[0-9]+\.[0-9]+\.[0-9]+\]' CHANGELOG.md | head -n 1 | sed -E 's/^## \[([0-9]+\.[0-9]+\.[0-9]+)\].*/\1/') | |
| echo "VERSION=$VERSION" | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| echo "::set-output name=version::$VERSION" | |
| - name: Lowercase repository owner | |
| id: repo_owner | |
| run: | | |
| REPO_OWNER_LOWER=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]') | |
| echo "REPO_OWNER_LOWER=$REPO_OWNER_LOWER" >> $GITHUB_ENV | |
| echo "::set-output name=repo_owner_lower::$REPO_OWNER_LOWER" | |
| - name: Build Docker image | |
| run: docker build -t ghcr.io/${{ steps.repo_owner.outputs.repo_owner_lower }}/${{ github.event.repository.name }}:${{ steps.changelog.outputs.version }} . | |
| - name: Push Docker image | |
| run: docker push ghcr.io/${{ steps.repo_owner.outputs.repo_owner_lower }}/${{ github.event.repository.name }}:${{ steps.changelog.outputs.version }} |