diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..dfc3895 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,52 @@ +name: Docker image build + +on: + push: + branches: [ "main" ] + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + paths: + - '**.php' + - './composer.*' + - './config/*' + - './.github/*' + pull_request: + branches: [ "main" ] + +env: + COMPOSER_AUTH: "{ \"github-oauth\": {\"github.com\": \"${{ secrets.HVG_DEV_GH_TOKEN }}\"}}" + +jobs: + pack-example: + name: Pack example! + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - uses: andrioid/setup-pack@latest + - name: Docker registry login + uses: docker/login-action@v1 + with: + registry: ghcr.io/hvg + username: hvg-dev + password: ${{ secrets.HVG_DEV_GH_TOKEN }} + - name: Set build environment + run: | + year=$(date +%Y); + month=$(date +%m); + ref="${GITHUB_REF#refs/*/}"; + echo "REF=$ref" >> $GITHUB_ENV; + tag="${GITHUB_REF#tags/*/}"; + [[ $tag == '' ]] || tag="${year}.${month}.${{ github.run_number }}"; + echo "TAG=$tag" >> $GITHUB_ENV; + - name: Build Image with pack + run: | + pack build ghcr.io/hvg/blog:$TAG \ + --builder heroku/builder-classic:22 \ + --descriptor project.toml \ + --workspace /app \ + --env COMPOSER_AUTH=$COMPOSER_AUTH; + - name: Tag Docker image to ref + run: | + docker tag ghcr.io/hvg/blog:$TAG ghcr.io/hvg/blog:$REF +