diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml new file mode 100644 index 0000000..c957067 --- /dev/null +++ b/.github/workflows/build-and-push.yml @@ -0,0 +1,28 @@ +name: Build and push Docker image + +on: + release: + types: [published] + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4.1.6 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3.2.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push Docker image + uses: docker/build-push-action@v5.3.0 + with: + context: . + push: true + tags: | + ghcr.io/${{ github.repository_owner }}/bus-map:latest + ghcr.io/${{ github.repository_owner }}/bus-map:${{ github.event.release.tag_name }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c957067..069e08b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,28 +1,61 @@ -name: Build and push Docker image +name: Bump Version and Create Release on: - release: - types: [published] + workflow_dispatch: + inputs: + type: + required: true + default: 'patch' + description: 'Bump type' + type: choice + options: + - patch + - minor + - major + +permissions: + packages: write + contents: write jobs: - build-and-push: + bump-version: runs-on: ubuntu-latest steps: - - name: Checkout + - name: Checkout repository uses: actions/checkout@v4.1.6 - - name: Login to GitHub Container Registry - uses: docker/login-action@v3.2.0 + - uses: pnpm/action-setup@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push Docker image - uses: docker/build-push-action@v5.3.0 + node-version: 23.x + cache: pnpm + + - name: Bump version + id: bump_version + run: | + pnpm version ${{ github.event.inputs.type }} -m "ci: bump version to %s" + echo "VERSION=$(node -p "require('./package.json').version")" >> "$GITHUB_ENV" + + - name: Push changes + run: | + git push origin main --follow-tags + + - name: Create a Release + uses: elgohr/Github-Release-Action@v5 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - context: . - push: true - tags: | - ghcr.io/${{ github.repository_owner }}/bus-map:latest - ghcr.io/${{ github.repository_owner }}/bus-map:${{ github.event.release.tag_name }} + title: Release ${{ env.VERSION }} + tag: ${{ env.VERSION }} + # - name: Create Release + # uses: actions/create-release@v1 + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # with: + # tag_name: v${{ env.VERSION }} + # release_name: Release v${{ env.VERSION }} + # body: 'Automated release based on version bump to v${{ env.VERSION }}.' + # draft: false + # prerelease: false diff --git a/Dockerfile b/Dockerfile index b56b5b2..2ec1f30 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:22-alpine as build +FROM node:23-alpine as build RUN npm install -g pnpm @@ -14,7 +14,7 @@ FROM node:22-alpine WORKDIR /app COPY --from=build /app/build build/ COPY --from=build /app/node_modules node_modules/ -COPY --from=build /app/package.json . +COPY --from=build /app/package.json . EXPOSE 3000 ENV NODE_ENV=production CMD ["node", "build"] \ No newline at end of file