feat: configuration comes from backend #26
Workflow file for this run
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 Docker Image | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| MANUAL_TAG: | |
| description: 'Optional manual tag to override versioning' | |
| required: false | |
| default: '' | |
| push: | |
| branches: | |
| - develop | |
| pull_request: | |
| branches: | |
| - develop | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| env: | |
| NEXUS_DOCKER_URL: ${{ secrets.NEXUS_DOCKER_URL }} | |
| NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }} | |
| NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }} | |
| DOCKER_API_NAME: 'infocompanies-api' | |
| steps: | |
| - name: Checkout source code | |
| uses: actions/checkout@v3 | |
| - name: Get the last Git tag | |
| id: get_last_tag | |
| run: | | |
| git fetch --tags --force | |
| LAST_TAG=$(git tag --sort=-creatordate | head -n 1) | |
| if [ -z "$LAST_TAG" ]; then | |
| LAST_TAG="0.0.0" | |
| fi | |
| echo "LAST_TAG=${LAST_TAG}" >> $GITHUB_ENV | |
| - name: Calculate new version | |
| id: calculate_version | |
| run: | | |
| LAST_TAG=${{ env.LAST_TAG }} | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$LAST_TAG" | |
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| PATCH=$((PATCH + 1)) | |
| else | |
| MINOR=$((MINOR + 1)) | |
| PATCH=0 | |
| fi | |
| NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" | |
| if [[ "${{ github.event.inputs.MANUAL_TAG }}" != "" ]]; then | |
| NEW_VERSION="${{ github.event.inputs.MANUAL_TAG}}" | |
| fi | |
| echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV | |
| - name: Build and push API image | |
| run: | | |
| IMAGE="${NEXUS_DOCKER_URL}/${DOCKER_API_NAME}:${NEW_VERSION}" | |
| docker build -f Dockerfile -t $IMAGE . | |
| echo "${NEXUS_PASSWORD}" | docker login "${NEXUS_DOCKER_URL}" -u "${NEXUS_USERNAME}" --password-stdin | |
| docker push $IMAGE | |
| docker logout "${NEXUS_DOCKER_URL}" | |
| - name: Create and push Git tag | |
| if: github.event_name != 'pull_request' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config user.name "GitHub Actions" | |
| git config user.email "actions@github.com" | |
| git tag -a "${NEW_VERSION}" -m "Release ${NEW_VERSION}" | |
| git push origin "${NEW_VERSION}" --no-verify | |
| - name: Output new version | |
| run: echo "New version is ${{ env.NEW_VERSION }}" |