| 1 | name: Build and Push Docker Image |
| 2 | |
| 3 | on: |
| 4 | push: |
| 5 | branches: |
| 6 | - master |
| 7 | paths: |
| 8 | - 'Dockerfile' |
| 9 | - 'GWVERSION' |
| 10 | pull_request: |
| 11 | paths: |
| 12 | - 'Dockerfile' |
| 13 | - 'GWVERSION' |
| 14 | |
| 15 | env: |
| 16 | IMAGE_NAME: pepijndevos/apicula |
| 17 | |
| 18 | jobs: |
| 19 | build: |
| 20 | runs-on: ubuntu-latest |
| 21 | permissions: |
| 22 | contents: read |
| 23 | packages: write |
| 24 | |
| 25 | steps: |
| 26 | - name: Checkout repository |
| 27 | uses: actions/checkout@v4 |
| 28 | |
| 29 | - name: Read Gowin IDE version from GWVERSION file |
| 30 | id: version |
| 31 | run: | |
| 32 | VERSION=$(cat GWVERSION) |
| 33 | if [ -z "$VERSION" ]; then |
| 34 | echo "Error: GWVERSION file is empty or does not exist" |
| 35 | exit 1 |
| 36 | fi |
| 37 | echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 38 | echo "Using Gowin IDE version: $VERSION" |
| 39 | |
| 40 | - name: Log in to Docker Hub |
| 41 | if: github.event_name == 'push' |
| 42 | uses: docker/login-action@v3 |
| 43 | with: |
| 44 | username: pepijndevos |
| 45 | password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 46 | |
| 47 | - name: Extract metadata (tags, labels) for Docker |
| 48 | id: meta |
| 49 | uses: docker/metadata-action@v5 |
| 50 | with: |
| 51 | images: ${{ env.IMAGE_NAME }} |
| 52 | tags: | |
| 53 | type=raw,value=${{ steps.version.outputs.version }} |
| 54 | type=raw,value=latest,enable={{is_default_branch}} |
| 55 | |
| 56 | - name: Build and push Docker image |
| 57 | uses: docker/build-push-action@v5 |
| 58 | with: |
| 59 | context: . |
| 60 | push: ${{ github.event_name == 'push' }} |
| 61 | build-args: | |
| 62 | GOWIN_VERSION=${{ steps.version.outputs.version }} |
| 63 | tags: ${{ steps.meta.outputs.tags }} |
| 64 | labels: ${{ steps.meta.outputs.labels }} |