|
| 1 | +name: Update version |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: '30 */4 * * *' |
| 7 | + |
| 8 | +jobs: |
| 9 | + update-version: |
| 10 | + name: Automatically get latest PHP-CS-Fixer version and commit |
| 11 | + |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: "Checkout code" |
| 16 | + uses: actions/checkout@v3 |
| 17 | + with: |
| 18 | + ref: master |
| 19 | + fetch-depth: '0' |
| 20 | + |
| 21 | + - name: "Update Dockerfile and action.yml" |
| 22 | + id: fetch_version |
| 23 | + run: | |
| 24 | + latest=$(curl -s https://packagist.org/packages/friendsofphp/php-cs-fixer.json|jq '[.package.versions[]|select(.version|test("^\\d+\\.\\d+\\.\\d+$"))|.version]|max_by(.|[splits("[.]")]|map(tonumber))') |
| 25 | + latest=$(echo $latest | tr -d '"') |
| 26 | + echo "Latest PHP-CS-Fixer version is $latest" |
| 27 | + echo ::set-output name=latest::$latest |
| 28 | + sed -i -re "s/ENV VERSION=.*/ENV VERSION=$latest/" Dockerfile |
| 29 | + cat Dockerfile |
| 30 | + sed -i -re "s/php-cs-fixer-ga:[0-9.]+/php-cs-fixer-ga:$latest/" action.yml |
| 31 | + cat action.yml |
| 32 | +
|
| 33 | + - name: "Commit changes" |
| 34 | + uses: stefanzweifel/git-auto-commit-action@v4 |
| 35 | + id: commit |
| 36 | + with: |
| 37 | + commit_author: "Oskar Stark <[email protected]>" |
| 38 | + commit_message: "Enhancement: Upgrade to PHP-CS-Fixer ${{ steps.fetch_version.outputs.latest }}" |
| 39 | + commit_user_email: "[email protected]" |
| 40 | + commit_user_name: "Oskar Stark" |
| 41 | + |
| 42 | + - name: "Tag version ${{ steps.fetch_version.outputs.latest }}" |
| 43 | + uses: "anothrNick/[email protected]" |
| 44 | + if: steps.commit.outputs.changes_detected == 'true' |
| 45 | + id: tag |
| 46 | + env: |
| 47 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + CUSTOM_TAG: ${{ steps.fetch_version.outputs.latest }} |
| 49 | + RELEASE_BRANCHES: master |
| 50 | + |
| 51 | + - name: "Create release ${{ steps.fetch_version.outputs.latest }}" |
| 52 | + uses: actions/create-release@v1 |
| 53 | + if: steps.commit.outputs.changes_detected == 'true' |
| 54 | + env: |
| 55 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + with: |
| 57 | + tag_name: ${{ steps.tag.outputs.new_tag }} |
| 58 | + release_name: ${{ steps.tag.outputs.new_tag }} |
| 59 | + commitish: master |
| 60 | + body: "Upgrade PHP-CS-Fixer to ${{ steps.tag.outputs.new_tag }}" |
| 61 | + |
| 62 | + publish_docker_images: |
| 63 | + needs: [update-version] |
| 64 | + runs-on: ubuntu-20.04 |
| 65 | + |
| 66 | + if: github.ref == 'refs/heads/master' || github.event_name == 'release' |
| 67 | + steps: |
| 68 | + - name: Checkout |
| 69 | + uses: actions/checkout@v3 |
| 70 | + - name: Docker meta |
| 71 | + id: meta |
| 72 | + uses: crazy-max/ghaction-docker-meta@v2 |
| 73 | + with: |
| 74 | + images: oskarstark/php-cs-fixer-ga |
| 75 | + tags: | |
| 76 | + type=raw,value=latest,enable=${{ endsWith(github.ref, 'master') }} |
| 77 | + type=ref,event=tag |
| 78 | + flavor: | |
| 79 | + latest=false |
| 80 | + - name: Login to DockerHub |
| 81 | + if: github.event_name != 'pull_request' |
| 82 | + uses: docker/login-action@v1 |
| 83 | + with: |
| 84 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 85 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 86 | + - name: Build and push |
| 87 | + uses: docker/build-push-action@v2 |
| 88 | + with: |
| 89 | + context: . |
| 90 | + push: ${{ github.event_name != 'pull_request' }} |
| 91 | + tags: ${{ steps.meta.outputs.tags }} |
| 92 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments