diff --git a/.github/workflows/check-create-pr.yml b/.github/workflows/check-create-pr.yml new file mode 100644 index 0000000..23b472d --- /dev/null +++ b/.github/workflows/check-create-pr.yml @@ -0,0 +1,58 @@ +name: Check and create PR + +on: + workflow_call: + inputs: + addon: + required: true + type: string + validate: + type: boolean + default: false + ref: + type: string + outputs: + ref: + value: ${{ jobs.pr.outputs.ref }} + description: The ref of the PR + url: + value: ${{ jobs.pr.outputs.url }} + description: The PR url + version: + value: ${{ jobs.check.outputs.remote_version }} + description: The addon's configured version. + secrets: + token: + required: true + workflow_dispatch: + inputs: + addon: + required: true + type: string + description: The addon slug. + validate: + type: boolean + description: Validate the config and dockerfile versions. + +jobs: + check: + name: Check addon for updates + uses: ./.github/workflows/check.yml + with: + addon: ${{ inputs.addon }} + validate: ${{ inputs.validate }} + ref: ${{ inputs.ref }} + secrets: + token: ${{ secrets.GITHUB_TOKEN }} + + pr: + name: Update addon files + needs: check + if: needs.check.outputs.local_version != needs.check.outputs.remote_version + uses: ./.github/workflows/create-pr.yml + with: + addon: ${{ inputs.addon }} + version: ${{ needs.check.outputs.remote_version }} + ref: ${{ inputs.ref }} + secrets: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/create-pr.yml b/.github/workflows/create-pr.yml new file mode 100644 index 0000000..cf2a604 --- /dev/null +++ b/.github/workflows/create-pr.yml @@ -0,0 +1,56 @@ +name: Create PR + +on: + workflow_call: + inputs: + addon: + required: true + type: string + version: + required: true + type: string + ref: + type: string + outputs: + url: + value: ${{ jobs.pr.outputs.url }} + description: The PR url + ref: + value: ${{ jobs.pr.outputs.ref }} + description: The ref of the PR + secrets: + token: + required: true + +jobs: + pr: + runs-on: ubuntu-latest + outputs: + url: ${{ steps.create.outputs.pull-request-url }} + ref: ${{ steps.create.outputs.pull-request-head-sha }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref || github.sha }} + token: ${{ secrets.token }} + - name: Update files + env: + NEW_VERSION: ${{ inputs.version }} + CONFIG_FILE: "${{ inputs.addon }}/config.json" + DOCKERFILE: "${{ inputs.addon }}/Dockerfile" + run: | + jq --arg version "$NEW_VERSION" '. + {version: $version}' "$CONFIG_FILE" > "${CONFIG_FILE}.new" + sed -i -e "/^FROM/s/:.*/:${NEW_VERSION}/" "$DOCKERFILE" + mv -f "${CONFIG_FILE}.new" "$CONFIG_FILE" + - id: create + name: Create Pull Request + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.token }} + branch: "update/${{ inputs.addon }}/${{ inputs.version }}" + delete-branch: true + path: "${{ inputs.addon }}/" + labels: docker,addon + commit-message: "Version bump ${{ inputs.addon }} to ${{ inputs.version }}" + title: "Version bump ${{ inputs.addon }} to ${{ inputs.version }}" + committer: "github-actions " diff --git a/.github/workflows/scheduled-check.yml b/.github/workflows/scheduled-check.yml index 511012e..fdf4bc7 100644 --- a/.github/workflows/scheduled-check.yml +++ b/.github/workflows/scheduled-check.yml @@ -4,21 +4,15 @@ on: schedule: - cron: '0 12 * * *' workflow_dispatch: - inputs: - publish: - type: boolean - default: true - description: Publish the updated addons. jobs: main: strategy: matrix: addon: [ sabnzbd, sonarr, radarr, lidarr ] - uses: ./.github/workflows/check-update-build.yml + uses: ./.github/workflows/check-create-pr.yml with: addon: ${{ matrix.addon }} - publish: ${{ github.event_name == 'schedule' || inputs.publish }} ref: ${{ github.ref }} secrets: token: ${{ secrets.GITHUB_TOKEN }}