Auto update the SPAShip CLI Version in Dockerfile #240
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: Auto update the SPAShip CLI Version in Dockerfile | |
| on: | |
| schedule: | |
| - cron: "0 0 * * *" | |
| workflow_dispatch: | |
| permissions: | |
| actions: write | |
| jobs: | |
| check-and-update: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Get latest @spaship/cli version | |
| id: fetch-version | |
| run: | | |
| LATEST_VERSION=$(curl -s https://registry.npmjs.org/@spaship/cli | jq -r '."dist-tags".latest') | |
| echo "latest_version=$LATEST_VERSION" >> $GITHUB_ENV | |
| - name: Extract current version from Dockerfile | |
| id: current-version | |
| run: | | |
| CURRENT_VERSION=$(grep -oP 'ARG SPASHIP_CLI_VERSION=\K[0-9.]+(?=$)' Dockerfile) | |
| echo "current_version=$CURRENT_VERSION" >> $GITHUB_ENV | |
| - name: Compare versions | |
| id: compare-versions | |
| run: | | |
| if [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then | |
| echo "update_needed=true" >> $GITHUB_ENV | |
| else | |
| echo "update_needed=false" >> $GITHUB_ENV | |
| fi | |
| - name: Update Dockerfile with new version | |
| if: env.update_needed == 'true' | |
| run: | | |
| sed -i "s/ARG SPASHIP_CLI_VERSION=.*/ARG SPASHIP_CLI_VERSION=$LATEST_VERSION/" Dockerfile | |
| - name: Commit and push changes | |
| if: env.update_needed == 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git add Dockerfile | |
| git commit -m "Update @spaship/cli to version $LATEST_VERSION" | |
| git push |