improve docker multi arch build time #3
Workflow file for this run
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: Release and Docker Publish | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: | |
| - dev | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build-and-release: | |
| # Only run if PR was merged and has a release label | |
| if: | | |
| github.event.pull_request.merged == true && ( | |
| contains(github.event.pull_request.labels.*.name, 'release:major') || | |
| contains(github.event.pull_request.labels.*.name, 'release:minor') || | |
| contains(github.event.pull_request.labels.*.name, 'release:patch') | |
| ) | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| id-token: write | |
| pull-requests: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 # Fetch all history for proper versioning | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Determine version bump from PR labels | |
| id: version_bump | |
| env: | |
| PR_LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }} | |
| run: | | |
| echo "PR Labels: $PR_LABELS" | |
| if echo "$PR_LABELS" | grep -q "release:major"; then | |
| echo "bump=major" >> $GITHUB_OUTPUT | |
| echo "Detected: MAJOR release" | |
| elif echo "$PR_LABELS" | grep -q "release:minor"; then | |
| echo "bump=minor" >> $GITHUB_OUTPUT | |
| echo "Detected: MINOR release" | |
| elif echo "$PR_LABELS" | grep -q "release:patch"; then | |
| echo "bump=patch" >> $GITHUB_OUTPUT | |
| echo "Detected: PATCH release" | |
| else | |
| echo "Error: No release label found" | |
| exit 1 | |
| fi | |
| - name: Generate version and metadata | |
| id: meta | |
| env: | |
| BUMP_TYPE: ${{ steps.version_bump.outputs.bump }} | |
| run: | | |
| # Get short commit SHA | |
| SHORT_SHA=$(git rev-parse --short HEAD) | |
| # Get version from previous release or default to v0.0.0 | |
| LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") | |
| echo "Latest tag: $LATEST_TAG" | |
| # Strip 'v' prefix and any existing commit hash/suffix | |
| CLEAN_VERSION=$(echo $LATEST_TAG | sed 's/^v//' | sed 's/-.*$//') | |
| # Parse version components | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$CLEAN_VERSION" | |
| # Bump version based on label | |
| case $BUMP_TYPE in | |
| major) | |
| MAJOR=$((MAJOR + 1)) | |
| MINOR=0 | |
| PATCH=0 | |
| ;; | |
| minor) | |
| MINOR=$((MINOR + 1)) | |
| PATCH=0 | |
| ;; | |
| patch) | |
| PATCH=$((PATCH + 1)) | |
| ;; | |
| esac | |
| # Create new version | |
| NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" | |
| VERSION="v${NEW_VERSION}-${SHORT_SHA}" | |
| CLEAN_VERSION_TAG="v${NEW_VERSION}" | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| echo "clean_version=${CLEAN_VERSION_TAG}" >> $GITHUB_OUTPUT | |
| echo "short_sha=${SHORT_SHA}" >> $GITHUB_OUTPUT | |
| echo "semver=${NEW_VERSION}" >> $GITHUB_OUTPUT | |
| echo "Generated version: ${VERSION}" | |
| echo "Clean version: ${CLEAN_VERSION_TAG}" | |
| - name: Extract Docker metadata | |
| id: docker_meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=${{ steps.meta.outputs.version }} | |
| type=raw,value=${{ steps.meta.outputs.clean_version }} | |
| type=raw,value=latest | |
| type=semver,pattern={{version}},value=${{ steps.meta.outputs.semver }} | |
| type=semver,pattern={{major}}.{{minor}},value=${{ steps.meta.outputs.semver }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
| push: true | |
| tags: ${{ steps.docker_meta.outputs.tags }} | |
| labels: ${{ steps.docker_meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Generate release notes | |
| id: release_notes | |
| env: | |
| PR_TITLE: ${{ github.event.pull_request.title }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| PR_URL: ${{ github.event.pull_request.html_url }} | |
| PR_AUTHOR: ${{ github.event.pull_request.user.login }} | |
| run: | | |
| # Get the last release tag | |
| LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || git rev-list --max-parents=0 HEAD) | |
| # Generate changelog | |
| CHANGELOG=$(git log ${LAST_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges) | |
| if [ -z "$CHANGELOG" ]; then | |
| CHANGELOG="- Initial release" | |
| fi | |
| # Create release notes | |
| cat << EOF > release_notes.md | |
| ## Release Info | |
| Released from PR [#${PR_NUMBER}](${PR_URL}): ${PR_TITLE} | |
| Author: @${PR_AUTHOR} | |
| ## Docker Images | |
| Available tags for this release: | |
| \`\`\`bash | |
| # Semantic version with commit SHA | |
| docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} | |
| # Clean semantic version | |
| docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.clean_version }} | |
| # Latest (always points to most recent release) | |
| docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
| \`\`\` | |
| ## Changes | |
| ${CHANGELOG} | |
| ## Installation | |
| ### Docker Compose | |
| Update your \`docker-compose.yml\`: | |
| \`\`\`yaml | |
| services: | |
| repovault: | |
| image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.clean_version }} | |
| restart: unless-stopped | |
| # ... rest of your config | |
| \`\`\` | |
| ### Docker Run | |
| \`\`\`bash | |
| docker run -d \\ | |
| --name repovault \\ | |
| --restart unless-stopped \\ | |
| -v ./config.yaml:/config/config.yaml:ro \\ | |
| -v ./backup:/backup:rw \\ | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.clean_version }} | |
| \`\`\` | |
| --- | |
| **Full Changelog**: https://github.com/${{ github.repository }}/compare/${LAST_TAG}...${{ steps.meta.outputs.clean_version }} | |
| EOF | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.meta.outputs.clean_version }} | |
| name: Release ${{ steps.meta.outputs.clean_version }} | |
| body_path: release_notes.md | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Release Summary | |
| run: | | |
| echo "## Release Published Successfully! :rocket:" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Version:** ${{ steps.meta.outputs.clean_version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**Commit:** ${{ steps.meta.outputs.short_sha }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**Type:** ${{ steps.version_bump.outputs.bump }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Docker Images" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.clean_version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |