From 43dacb381898f6078a79ffbb74fbca3499ea27cd Mon Sep 17 00:00:00 2001 From: Flomp Date: Sun, 5 Jan 2025 18:31:34 +0100 Subject: [PATCH] Adds Github Actions (#148) adds github actions --- .github/workflows/release.yaml | 137 +++++++++++++++++++++++++++++++++ docs/Dockerfile | 2 +- web/Dockerfile | 2 +- 3 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..d5e8e759 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,137 @@ +name: Release Workflow + +on: + workflow_dispatch: + inputs: + version: + description: "The version to release (e.g., 0.12.0)" + required: true + +jobs: + # Job 1: Bump Versions and Create Tags + versioning: + runs-on: ubuntu-latest + + outputs: + version: ${{ steps.set_version.outputs.version }} + + steps: + # 1. Checkout the repository + - name: Checkout code + uses: actions/checkout@v3 + + # 2. Setup node & npm + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '22' + + # 3. Bump versions using npm + - name: Bump version in web and docs + id: set_version + run: | + VERSION=${{ github.event.inputs.version }} + cd web && npm version $VERSION --no-git-tag-version && cd .. + cd docs && npm version $VERSION --no-git-tag-version && cd .. + echo "version=v$VERSION" >> $GITHUB_OUTPUT + + # 4. Tag and push the new versions + - name: Commit and Tag + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add web/package.json docs/package.json + git commit -m "Release ${{ github.event.inputs.version }}" + git tag "v${{ github.event.inputs.version }}" + git push origin main --tags + + # Job 2: Build Docker Images + docker-build: + runs-on: ubuntu-latest + needs: versioning + + steps: + # 1. Checkout the repository + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: '1.22' + + # 2. Log in to Docker Hub + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # 3. Setup docker multi platform builds + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # 4. Build and push Docker images + - name: Build Docker Images + env: + VERSION: ${{ needs.versioning.outputs.version }} + run: | + # Build search image + docker buildx build search/ --no-cache -t flomp/wanderer-search:v$VERSION -t flomp/wanderer-search:latest --platform=linux/amd64,linux/arm64 --push + + # Build db image + cd db + env GOOS=linux GOARCH=arm64 go build -o pocketbase_arm64 + env GOOS=linux GOARCH=amd64 go build -o pocketbase_amd64 + cd .. + docker buildx build db/ --no-cache -t flomp/wanderer-db:v$VERSION -t flomp/wanderer-db:latest --platform=linux/amd64,linux/arm64 --push + + # Build web image + export PUBLIC_VALHALLA_URL=https://valhalla1.openstreetmap.de + cd web + npm ci && npm run build + cd .. + docker buildx build web/ --no-cache -t flomp/wanderer-web:v$VERSION -t flomp/wanderer-web:latest --platform=linux/amd64,linux/arm64 --push + + # Build docs image + cd docs + npm ci && npm run build + cd .. + docker buildx build docs/ --no-cache -t flomp/wanderer-docs:v$VERSION -t flomp/wanderer-docs:latest --platform=linux/amd64,linux/arm64 --push + + # Job 3: Publish the Release + release: + runs-on: ubuntu-latest + needs: [versioning, docker-build] + + steps: + # 1. Checkout the repository + - name: Checkout code + uses: actions/checkout@v3 + + # 2. Extract release notes from CHANGELOG.md + - name: Extract release notes + id: changelog + run: | + VERSION="${{ needs.versioning.outputs.version }}" + CHANGELOG=$(awk -v ver="$VERSION" ' + BEGIN { in_section = 0 } + /^# / { + if (in_section) exit + if ($2 == ver) in_section = 1 + } + in_section { print } + ' CHANGELOG.md) + echo "changelog=$CHANGELOG" >> $GITHUB_OUTPUT + + # 3. Create GitHub Release + - name: Create GitHub Release + uses: actions/create-release@v1 + with: + tag_name: ${{ needs.versioning.outputs.version }} + release_name: "v${{ needs.versioning.outputs.version }}" + body: ${{ steps.changelog.outputs.changelog }} + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/docs/Dockerfile b/docs/Dockerfile index 119a72e9..e1b5a6f0 100644 --- a/docs/Dockerfile +++ b/docs/Dockerfile @@ -1,4 +1,4 @@ -FROM node:slim AS runtime +FROM node:22-alpine AS base WORKDIR /app COPY ./dist dist/ diff --git a/web/Dockerfile b/web/Dockerfile index 9592a1d5..bf6d2eef 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18-alpine +FROM node:22-alpine WORKDIR /app COPY ./build build/ COPY package*.json .