fix(cicd) docker auto version #12
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 ci docker image | |
| on: | |
| workflow_dispatch: | |
| push: | |
| paths: | |
| - '.github/ci.Dockerfile' | |
| branches: | |
| - main | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| steps: | |
| - name: checkout code | |
| uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4 | |
| - name: setup bun | |
| uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76 # v2 | |
| with: | |
| bun-version: 'latest' | |
| - name: version bump | |
| id: version-bump | |
| run: | | |
| git fetch origin main | |
| git checkout main | |
| git pull origin main --ff-only | |
| BUILDTIME=$(date -u +%Y-%m-%d) | |
| LINE=$(awk '/org.opencontainers.image.created/ { print NR; exit }' .github/ci.Dockerfile) | |
| sed -i "${LINE}c\LABEL org.opencontainers.image.created=\"${BUILDTIME}\"" .github/ci.Dockerfile | |
| echo "buildtime=$BUILDTIME" >> "$GITHUB_OUTPUT" | |
| git add .github/ci.Dockerfile | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| COMMIT_NAME="${{ github.event.head_commit.author.name }}" | |
| COMMIT_EMAIL="${{ github.event.head_commit.author.email }}" | |
| if [ -z "$COMMIT_NAME" ]; then | |
| COMMIT_NAME="${{ github.actor }}" | |
| COMMIT_EMAIL="${{ github.actor }}@users.noreply.github.com" | |
| fi | |
| if [ -z "${{ github.event.head_commit.message }}" ]; then | |
| COMMIT_MSG="${{ github.event.head_commit.message }}" | |
| else | |
| COMMIT_MSG="$(git log -1 --pretty=%s || true)" | |
| fi | |
| if [ -z "$COMMIT_MSG" ]; then | |
| COMMIT_MSG="chore(ci.container) docker build" | |
| fi | |
| git config --global user.name "$COMMIT_NAME" | |
| git config --global user.email "$COMMIT_EMAIL" | |
| git commit --author="$COMMIT_NAME <$COMMIT_EMAIL>" -m "$COMMIT_MSG" | |
| git push | |
| fi | |
| - name: set up docker buildx | |
| uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3 | |
| - name: github container registry login | |
| uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.PKG_TOKEN }} | |
| - name: build and push | |
| uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5 | |
| with: | |
| context: . | |
| file: .github/ci.Dockerfile | |
| push: true | |
| labels: ${{ steps.meta.outputs.labels }} | |
| tags: ghcr.io/${{ github.repository }}/ci:latest | |
| annotations: | | |
| org.opencontainers.image.description=CI worker base image for vitetest & playwright, unit & e2e testing | |
| org.opencontainers.image.authors=https://github.com/xero/text0wnz/graphs/contributors | |
| org.opencontainers.image.documentation=https://github.com/xero/text0wnz/wiki | |
| org.opencontainers.image.source=https://github.com/xero/text0wnz | |
| org.opencontainers.image.licenses=MIT | |
| org.opencontainers.image.title=text0wnz | |
| org.opencontainers.image.url=https://text.0w.nz | |
| org.opencontainers.image.created="${{ steps.version-bump.outputs.buildtime }}" |