|
7 | 7 | - main |
8 | 8 | - release/* |
9 | 9 |
|
10 | | - |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + pull-requests: write |
| 13 | + packages: write |
11 | 14 |
|
12 | 15 | jobs: |
13 | | - build_and_release: |
| 16 | + release-and-tag: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + version: ${{ steps.release.outputs.version }} |
| 20 | + steps: |
| 21 | + - name: Checkout Repository |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: '0' |
| 25 | + - name: Set up JDK |
| 26 | + uses: actions/setup-java@v4 |
| 27 | + with: |
| 28 | + java-version: '21' |
| 29 | + distribution: 'corretto' |
| 30 | + cache: 'maven' |
| 31 | + |
| 32 | + - name: Configure Git user |
| 33 | + run: | |
| 34 | + git config user.email "actions@github.com" |
| 35 | + git config user.name "GitHub Actions" |
| 36 | +
|
| 37 | + - name: Prepare Release |
| 38 | + id: release |
| 39 | + run: | |
| 40 | + # Get current version from pom.xml |
| 41 | + CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 42 | + echo "Current version: $CURRENT_VERSION" |
| 43 | + |
| 44 | + # Remove -SNAPSHOT and calculate next version |
| 45 | + VERSION=${CURRENT_VERSION%-SNAPSHOT} |
| 46 | + IFS='.' read -r major minor patch <<< "$VERSION" |
| 47 | + NEXT_VERSION="$major.$minor.$((patch + 1))-SNAPSHOT" |
| 48 | + |
| 49 | + # Perform release |
| 50 | + mvn -B release:prepare release:perform \ |
| 51 | + -DreleaseVersion=$VERSION \ |
| 52 | + -DdevelopmentVersion=$NEXT_VERSION \ |
| 53 | + -DtagNameFormat=v@{project.version} \ |
| 54 | + -DpushChanges=true \ |
| 55 | + -DlocalCheckout=true \ |
| 56 | + -DpreparationGoals="clean verify" \ |
| 57 | + -DskipTests |
| 58 | + |
| 59 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 60 | + echo "Released version $VERSION" |
| 61 | +
|
| 62 | + build-and-push-docker-image: |
| 63 | + needs: release-and-tag |
14 | 64 | runs-on: ubuntu-latest |
15 | 65 | steps: |
16 | | - - name: Checkout code |
17 | | - uses: actions/checkout@v3 |
| 66 | + - name: Checkout Repository |
| 67 | + uses: actions/checkout@v4 |
18 | 68 |
|
19 | 69 | - name: Set up QEMU |
20 | 70 | uses: docker/setup-qemu-action@v3 |
|
31 | 81 | username: ${{ secrets.DOCKER_USERNAME }} |
32 | 82 | password: ${{ secrets.DOCKER_PASSWORD }} |
33 | 83 |
|
34 | | - - name: Determine the version tag |
35 | | - id: version |
36 | | - run: | |
37 | | - if [ "${{ github.event_name }}" = "release" ]; then |
38 | | - echo "Using release tag: ${{ github.ref_name }}" |
39 | | - echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT |
40 | | - else |
41 | | - echo "No release detected. Using tag: latest" |
42 | | - echo "version=latest" >> $GITHUB_OUTPUT |
43 | | - fi |
44 | | -
|
45 | 84 | - name: Build and push Docker image |
46 | 85 | uses: docker/build-push-action@v6 |
47 | 86 | with: |
|
50 | 89 | cache-to: type=gha, scope=data-viz-admin |
51 | 90 | context: . |
52 | 91 | push: true |
53 | | - tags: ${{ vars.DOCKER_REGISTRY }}/data-viz-admin:${{ steps.version.outputs.version }} |
54 | | - |
| 92 | + build-args: | |
| 93 | + VERSION=${{ needs.release-and-tag.outputs.version }} |
| 94 | + TAG=${{ needs.release-and-tag.outputs.version }} |
| 95 | + tags: | |
| 96 | + ${{ vars.DOCKER_REGISTRY }}/data-viz-admin:latest |
| 97 | + ${{ vars.DOCKER_REGISTRY }}/data-viz-admin:v${{ needs.release-and-tag.outputs.version }} |
0 commit comments