|
| 1 | +name: 'Release' |
| 2 | +description: 'Update version, publish release and push docker image' |
| 3 | +inputs: |
| 4 | + version_increment: |
| 5 | + description: 'La version a incrémenter (major, minor, patch)' |
| 6 | + required: true |
| 7 | + default: 'patch' |
| 8 | + |
| 9 | + build_docker_image: |
| 10 | + description: "Construire l'image docker ?" |
| 11 | + required: true |
| 12 | + default: 'true' |
| 13 | + |
| 14 | + latest: |
| 15 | + description: "Tagger l'image docker avec le tag 'latest' ?" |
| 16 | + required: true |
| 17 | + default: 'true' |
| 18 | + |
| 19 | + repository: |
| 20 | + description: 'Repository to the project' |
| 21 | + required: true |
| 22 | + |
| 23 | + username: |
| 24 | + description: 'Username to the project' |
| 25 | + required: true |
| 26 | + |
| 27 | + password: |
| 28 | + description: 'Password to the project' |
| 29 | + required: true |
| 30 | + |
| 31 | + github_token: |
| 32 | + description: 'Github token to the project' |
| 33 | + required: true |
| 34 | + |
| 35 | + registry: |
| 36 | + description: 'Docker registry base url' |
| 37 | + default: 'ghcr.io' |
| 38 | + required: false |
| 39 | + |
| 40 | + context: |
| 41 | + description: 'Docker context' |
| 42 | + default: '.' |
| 43 | + required: false |
| 44 | + |
| 45 | + args: |
| 46 | + description: 'Docker build args' |
| 47 | + default: '' |
| 48 | + required: false |
| 49 | + |
| 50 | + is_branch_protected: |
| 51 | + description: 'Push on a protected branch ? (required github_token)' |
| 52 | + default: false |
| 53 | + required: false |
| 54 | + |
| 55 | +runs: |
| 56 | + using: 'composite' |
| 57 | + steps: |
| 58 | + - name: Checkout repository |
| 59 | + uses: actions/checkout@v4 |
| 60 | + with: |
| 61 | + repository: ${{ inputs.repository }} |
| 62 | + |
| 63 | + - name: Checkout code |
| 64 | + uses: actions/checkout@v4 |
| 65 | + |
| 66 | + - name: Set up Git |
| 67 | + shell: bash |
| 68 | + run: | |
| 69 | + git config user.email "github@action.com" |
| 70 | + git config user.name "Github Action" |
| 71 | + echo ${{ inputs.github_token }} > token.txt |
| 72 | + git config credential.helper "store --file=token.txt" |
| 73 | +
|
| 74 | + - name: Update version |
| 75 | + shell: bash |
| 76 | + run: | |
| 77 | + echo NEW_VERSION=$(yarn version --${{ inputs.version_increment }} --json | jq -r '.data | select(contains("New version")) | split(":")[1] | gsub(" ";"")') >> $GITHUB_ENV |
| 78 | + env: |
| 79 | + REF: ${{ github.ref }} |
| 80 | + |
| 81 | + - name: Push to unprotected branch |
| 82 | + if: inputs.is_branch_protected == 'false' |
| 83 | + shell: bash |
| 84 | + run: | |
| 85 | + git push --follow-tags |
| 86 | + env: |
| 87 | + REF: ${{ github.ref }} |
| 88 | + |
| 89 | + - name: Push to protected branch |
| 90 | + if: inputs.is_branch_protected == 'true' |
| 91 | + uses: CasperWA/push-protected@v2 |
| 92 | + with: |
| 93 | + token: ${{ inputs.github_token }} |
| 94 | + branch: main |
| 95 | + unprotect_reviews: true |
| 96 | + tags: true |
| 97 | + |
| 98 | + - name: Publish release |
| 99 | + uses: ncipollo/release-action@v1 |
| 100 | + with: |
| 101 | + name: Release ${{ env.NEW_VERSION }} |
| 102 | + commit: ${{ env.REF }} |
| 103 | + draft: false |
| 104 | + prerelease: false |
| 105 | + generateReleaseNotes: true |
| 106 | + token: ${{ inputs.github_token }} |
| 107 | + makeLatest: ${{ inputs.latest }} |
| 108 | + tag: ${{ env.NEW_VERSION }} |
| 109 | + |
| 110 | + - name: Get repo name |
| 111 | + shell: bash |
| 112 | + id: get_repo_name |
| 113 | + run: | |
| 114 | + echo "REPO_NAME=$(basename "${{ inputs.repository }}")" >> $GITHUB_ENV |
| 115 | +
|
| 116 | + - name: Get repo full name |
| 117 | + shell: bash |
| 118 | + id: get_repo_full_name |
| 119 | + run: | |
| 120 | + FULL_NAME=$(echo "${{ inputs.repository }}" | tr '[:upper:]' '[:lower:]') |
| 121 | + echo "REPO_FULL_NAME=$FULL_NAME" >> $GITHUB_ENV |
| 122 | +
|
| 123 | + - name: Get current date and time |
| 124 | + shell: bash |
| 125 | + id: get_current_date_time |
| 126 | + run: | |
| 127 | + echo "CURRENT_DATE_TIME=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV |
| 128 | +
|
| 129 | + - name: Define tags |
| 130 | + shell: bash |
| 131 | + id: define_tags |
| 132 | + run: | |
| 133 | + if [ "${{ inputs.latest }}" = "true" ]; then |
| 134 | + echo "TAGS=ghcr.io/${{ env.REPO_FULL_NAME }}:${{ env.NEW_VERSION }},ghcr.io/${{ env.REPO_FULL_NAME }}:latest,ghcr.io/${{ env.REPO_FULL_NAME }}:unstable" >> $GITHUB_ENV |
| 135 | + else |
| 136 | + echo "TAGS=ghcr.io/${{ env.REPO_FULL_NAME }}:${{ env.NEW_VERSION }},ghcr.io/${{ env.REPO_FULL_NAME }}:unstable" >> $GITHUB_ENV |
| 137 | + fi |
| 138 | + env: |
| 139 | + NEW_VERSION: ${{ env.NEW_VERSION }} |
| 140 | + REPO_NAME: ${{ env.REPO_NAME }} |
| 141 | + REPO_FULL_NAME: ${{ env.REPO_FULL_NAME }} |
| 142 | + |
| 143 | + - name: Set up QEMU |
| 144 | + if: ${{ inputs.build_docker_image == 'true' }} |
| 145 | + uses: docker/setup-qemu-action@v3 |
| 146 | + |
| 147 | + - name: Set up Docker Buildx |
| 148 | + if: ${{ inputs.build_docker_image == 'true' }} |
| 149 | + uses: docker/setup-buildx-action@v3.10.0 |
| 150 | + |
| 151 | + - name: Log in to the Container registry |
| 152 | + if: ${{ inputs.build_docker_image == 'true' }} |
| 153 | + uses: docker/login-action@v3 |
| 154 | + with: |
| 155 | + registry: ${{ inputs.registry }} |
| 156 | + username: ${{ inputs.username }} |
| 157 | + password: ${{ inputs.password }} |
| 158 | + env: |
| 159 | + REGISTRY: ${{ inputs.registry }} |
| 160 | + |
| 161 | + - name: Build and push Docker image |
| 162 | + if: ${{ inputs.build_docker_image == 'true' }} |
| 163 | + uses: docker/build-push-action@v6.18.0 |
| 164 | + with: |
| 165 | + context: ${{ inputs.context }} |
| 166 | + push: true |
| 167 | + tags: ${{ env.TAGS }} |
| 168 | + build-args: ${{ inputs.args }} |
| 169 | + platforms: linux/amd64 |
| 170 | + env: |
| 171 | + TAGS: ${{ env.TAGS }} |
0 commit comments