|
| 1 | +name: build-and-push-container-image |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: |
| 5 | + - closed |
| 6 | +jobs: |
| 7 | + build-and-push-container-image: |
| 8 | + name: Build and push container image |
| 9 | + runs-on: ubuntu-latest |
| 10 | + if: | |
| 11 | + github.event_name == 'pull_request' && |
| 12 | + github.event.pull_request.merged == true && |
| 13 | + github.base_ref == inputs.on_base_ref && |
| 14 | + github.event.action == 'closed' && |
| 15 | + ( |
| 16 | + contains(github.event.pull_request.labels.*.name, 'major') || |
| 17 | + contains(github.event.pull_request.labels.*.name, 'minor') || |
| 18 | + contains(github.event.pull_request.labels.*.name, 'patch') |
| 19 | + ) && |
| 20 | + !contains(github.event.pull_request.labels.*.name, 'chore') |
| 21 | + steps: |
| 22 | + - name: Checkout GIT repository |
| 23 | + uses: actions/checkout@v3 |
| 24 | + - name: Get the application version |
| 25 | + id: application-version |
| 26 | + run: | |
| 27 | + image_version=$(grep "^LABEL site.local.program.version=" Dockerfile | cut -d= -f2 | sed -e 's/"//g') |
| 28 | + if [ -z "${image_version}" ]; then |
| 29 | + echo "ERROR: unable to detect version number!" >&2 |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | + echo "tag=${image_version}" >> $GITHUB_OUTPUT |
| 33 | + - name: Build container image |
| 34 | + run: docker build . --file Dockerfile --tag oitc/modbus-server:${{steps.application-version.outputs.tag}} |
| 35 | + - name: Login to container registry |
| 36 | + run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin |
| 37 | + - name: Push container image to container registry |
| 38 | + run: docker push oitc/modbus-server:${{steps.application-version.outputs.tag}} |
0 commit comments