diff --git a/.forgejo/forgejo-release-sync/action.yml b/.forgejo/forgejo-release-sync/action.yml new file mode 100644 index 00000000..1ade63ed --- /dev/null +++ b/.forgejo/forgejo-release-sync/action.yml @@ -0,0 +1,111 @@ +# Copyright The Forgejo Authors +# SPDX-License-Identifier: MIT + +name: 'Sync with Forgejo releases' +author: 'Forgejo authors' + +inputs: + forgejo: + description: 'URL of the Forgejo instance' + required: true + repository: + description: 'Repository of the Forgejo documentation' + required: true + token: + description: 'Token with repository and issues write permissions to the repository' + required: true + api: + description: 'curl command to the API' + required: true + today: + description: 'todays date as YYYY-MM-DD' + dry-run: + description: 'set to echo to do display commands instead of carrying them out' + verbose: + description: 'Increase the verbosity level' + default: 'false' + +outputs: + releases: + value: '${{ steps.releases.outputs.value }}' + branches-add: + value: '${{ steps.branches-add.outputs.value }}' + labels-archive: + value: '${{ steps.labels-archive.outputs.value }}' + labels-add: + value: '${{ steps.labels-add.outputs.value }}' + +runs: + using: 'composite' + steps: + - name: apt install jq + run: | + ${{ inputs.verbose }} && set -x + if ! which jq ; then + export DEBIAN_FRONTEND=noninteractive + apt-get update -qq + apt-get -q install -y -qq jq + fi + + - name: forgejo release schedule + run: | + ${{ inputs.verbose }} && set -x + curl --fail -sS -o release-schedule.json https://codeberg.org/forgejo/docs/raw/branch/next/release-schedule.json + cat release-schedule.json + + - name: current forgejo releases + id: releases + run: | + ${{ inputs.verbose }} && set -x + today=${{ inputs.today }} + if test -z "$today"; then + today=$(date +%F) + fi + jq --raw-output '.[] | select(.eol > "'$today'" and .cut <= "'$today'") | "\(.major).\(.minor)"' < release-schedule.json | sort | tee releases-current.txt + echo value=$(cat releases-current.txt) >> $GITHUB_OUTPUT + + - name: get existing stable branches + run: | + ${{ inputs.verbose }} && set -x + ${{ inputs.api }}/branches | jq --raw-output '.[] | select(.name | startswith("v")) | .name' | sed -e 's/^v//' | sort | tee docs-branches.txt + + - name: add missing stable branches + id: branches-add + run: | + ${{ inputs.verbose }} && set -x + > value + comm -23 releases-current.txt docs-branches.txt | while read version ; do + ${{ inputs.dry-run }} ${{ inputs.api }}/branches -X POST --data '{"new_branch_name":"v'$version'","old_branch_name":"next"}' + echo $version >> value + done + echo value=$(cat value) >> $GITHUB_OUTPUT + + - name: get existing backport labels + run: | + ${{ inputs.verbose }} && set -x + ${{ inputs.api }}/labels | jq --raw-output '.[] | select((.is_archived == false) and (.name | startswith("backport/"))) | "\(.name) \(.id)"' | sed -e 's|^backport/v||' | sort | tee docs-backport-labels.txt + + - name: archive old backport labels + id: labels-archive + run: | + ${{ inputs.verbose }} && set -x + > value + cat docs-backport-labels.txt | while read version id ; do + if grep --quiet "^$version$" releases-current.txt ; then + continue + fi + echo $version >> value + ${{ inputs.dry-run }} ${{ inputs.api }}/labels/$id -X PATCH --data '{"is_archived": true}' + done + echo value=$(cat value) >> $GITHUB_OUTPUT + + - name: add missing backport labels + id: labels-add + run: | + ${{ inputs.verbose }} && set -x + > value + cut -f1 -d' ' docs-backport-labels.txt | comm -23 releases-current.txt - | while read version ; do + ${{ inputs.dry-run }} ${{ inputs.api }}/labels -X POST --data '{"name":"backport/v'$version'","description":"Automated backport to the v'$version'docs","color":"#bfe5bf"}' + echo $version >> value + done + echo value=$(cat value) >> $GITHUB_OUTPUT diff --git a/.forgejo/workflows/forgejo-release-sync-test.yml b/.forgejo/workflows/forgejo-release-sync-test.yml new file mode 100644 index 00000000..013c2c6c --- /dev/null +++ b/.forgejo/workflows/forgejo-release-sync-test.yml @@ -0,0 +1,120 @@ +# Copyright The Forgejo Authors +# SPDX-License-Identifier: MIT + +name: forgejo-release + +# +# Changing this workflow must not be from a fork otherwise the secret +# won't be available to write in the playground: +# +# * push to a branch of this repository +# * open a pull request +# + +on: + pull_request: + paths: + - .forgejo/forgejo-release-sync/** + - .forgejo/workflows/forgejo-release-sync*.yml + +env: + FORGEJO: https://codeberg.org + REPOSITORY: forgejo-contrib/docs-playground + API: "curl --fail -sS -H 'Content-Type: application/json' -H 'Authorization: Bearer ${{ secrets.DOCS_PLAYGROUND_TOKEN }}' ${{ env.FORGEJO }}/api/v1/repos/${{ env.REPOSITORY }}" + +jobs: + sync-test: + runs-on: docker + container: + image: 'code.forgejo.org/oci/node:20-bookworm' + steps: + - uses: https://code.forgejo.org/actions/checkout@v4 + + - name: apt install jq + run: | + export DEBIAN_FRONTEND=noninteractive + apt-get update -qq + apt-get -q install -y -qq jq + + - name: setup fixture + run: | + set -x + ${{ env.API }}/branches | jq --raw-output '.[] | select(.protected == false) | .name' | while read branch ; do + ${{ env.API }}/branches/$branch -X DELETE + done + ${{ env.API }}/labels | jq --raw-output '.[] | .id' | while read label ; do + ${{ env.API }}/labels/$label -X DELETE + done + + - name: dry run sync + id: sync-dry-run + uses: ./.forgejo/forgejo-release-sync + with: + forgejo: ${{ env.FORGEJO }} + repository: ${{ env.REPOSITORY }} + token: ${{ secrets.DOCS_PLAYGROUND_TOKEN }} + api: ${{ env.API }} + dry-run: echo + verbose: true + + - name: assert dry run sync + run: | + set -x + test "${{ steps.sync-dry-run.outputs.releases }}" + + # 7.0 and 9.0 are stable + - name: 2024-11-22 sync + id: sync-2024-11-22 + uses: ./.forgejo/forgejo-release-sync + with: + forgejo: ${{ env.FORGEJO }} + repository: ${{ env.REPOSITORY }} + token: ${{ secrets.DOCS_PLAYGROUND_TOKEN }} + api: ${{ env.API }} + today: 2024-11-22 + verbose: true + + - name: 2024-11-22 assert + run: | + set -x + test "${{ steps.sync-2024-11-22.outputs.branches-add }}" = "7.0 9.0" + test "${{ steps.sync-2024-11-22.outputs.labels-archive }}" = "" + test "${{ steps.sync-2024-11-22.outputs.labels-add }}" = "7.0 9.0" + + # 7.0 and 9.0 are stable and the 10.0 branch is cut + - name: 2024-12-31 sync + id: sync-2024-12-31 + uses: ./.forgejo/forgejo-release-sync + with: + forgejo: ${{ env.FORGEJO }} + repository: ${{ env.REPOSITORY }} + token: ${{ secrets.DOCS_PLAYGROUND_TOKEN }} + api: ${{ env.API }} + today: 2024-12-31 + verbose: true + + # 7.0 and 10.0 are stable and 9.0 is EOL + - name: 2024-12-31 assert + run: | + set -x + test "${{ steps.sync-2024-12-31.outputs.branches-add }}" = "10.0" + test "${{ steps.sync-2024-12-31.outputs.labels-archive }}" = "" + test "${{ steps.sync-2024-12-31.outputs.labels-add }}" = "10.0" + + - name: 2025-01-28 sync + id: sync-2025-01-28 + uses: ./.forgejo/forgejo-release-sync + with: + forgejo: ${{ env.FORGEJO }} + repository: ${{ env.REPOSITORY }} + token: ${{ secrets.DOCS_PLAYGROUND_TOKEN }} + api: ${{ env.API }} + today: 2025-01-28 + verbose: true + + - name: 2025-01-28 assert + run: | + set -x + test "${{ steps.sync-2025-01-28.outputs.branches-add }}" = "" + test "${{ steps.sync-2025-01-28.outputs.labels-archive }}" = "9.0" + test "${{ steps.sync-2025-01-28.outputs.labels-add }}" = "" diff --git a/.forgejo/workflows/forgejo-release-sync.yml b/.forgejo/workflows/forgejo-release-sync.yml new file mode 100644 index 00000000..b70ecf5f --- /dev/null +++ b/.forgejo/workflows/forgejo-release-sync.yml @@ -0,0 +1,37 @@ +# Copyright The Forgejo Authors +# SPDX-License-Identifier: MIT + +# +# Keep the docs repository up to date based on the Forgejo schedule release +# found at https://codeberg.org/forgejo/docs/raw/branch/next/release-schedule.json +# +# * cut documentation branches at the same time as the Forgejo main repository +# * create and archive the backport labels +# * ... +# + +name: forgejo-release + +on: + # schedule: + # - cron: '15 5 * * *' + workflow_dispatch: + +env: + FORGEJO: https://codeberg.org + REPOSITORY: forgejo/docs + API: "curl --fail -sS -H 'Content-Type: application/json' -H 'Authorization: Bearer ${{ secrets.WEBSITETOKEN }}' ${{ env.FORGEJO }}/api/v1/repos/${{ env.REPOSITORY }}" + +jobs: + sync: + if: secrets.WEBSITETOKEN != '' + runs-on: docker + container: + image: 'code.forgejo.org/oci/node:20-bookworm' + steps: + - uses: ./.forgejo/forgejo-release-sync + with: + forgejo: ${{ env.FORGEJO }} + repository: ${{ env.REPOSITORY }} + api: ${{ env.API }} + dry-run: ${{ vars.FORGEJO_RELEASE_DRY_RUN }}