diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..d90a399 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Exclude for archive generation +/.git* export-ignore diff --git a/.github/workflows/versions.yaml b/.github/workflows/versions.yaml new file mode 100644 index 0000000..2f32be6 --- /dev/null +++ b/.github/workflows/versions.yaml @@ -0,0 +1,89 @@ +name: Versions + +on: + workflow_dispatch: + inputs: + dry-run: + required: true + type: boolean + default: true + # schedule: + # - cron: '*/10 * * * *' + +jobs: + sync: + name: Sync + runs-on: ubuntu-latest + outputs: + tags-matrix: steps.tags-matrix.outputs.result + latest-release: steps.latest-release.outputs.result + steps: + - name: Get upstream package name + id: package + run: echo "::set-output name=package-name::$(jq -r '.require | map_values(select(. == "self.version")) | keys[0]' composer.json)" + + - name: Generate diff of versions arrays + id: tags-matrix + uses: actions/github-script@v6 + env: + PACKAGE: ${{ steps.package.outputs.package-name }} + with: + script: | + const { PACKAGE } = process.env + const currrentTags = github.rest.repos.listTags({ + owner: context.repo.owner, + repo: context.repo.repo, + }) + const upstreamTags = github.rest.repos.listTags({ + owner: context.repo.owner, + repo: PACKAGE.substring(str.indexOf('/') + 1), + per_page: 15 + }) + return upstreamTags.filter((tag) => !currrentTags.includes(tag)) + + - name: Extract latest release + id: latest-release + env: + TAGS: ${{ steps.tags-matrix.outputs.result }} + run: echo "::set-output name=result::$(jq -r '.[0]' <<< "$TAGS")" + + tags: + name: Tags + runs-on: ubuntu-latest + needs: + - sync + if: needs.sync.outputs.tags-matrix + strategy: + fail-fast: false + matrix: + tag: ${{ fromJSON(needs.sync.outputs.tags-matrix) }} + steps: + - name: Create a tag + uses: rickstaa/action-create-tag@v1 + if: ${{ ! inputs.dry-run }} + with: + tag: ${{ matrix.tag }} + message: ${{ matrix.tag }} + + release: + name: Release + runs-on: ubuntu-latest + needs: + - sync + - tags + if: needs.sync.outputs.latest-release + steps: + - name: Generate token + uses: tibdex/github-app-token@v1 + id: generate-token + with: + app_id: ${{ secrets.BOT_APP_ID }} + private_key: ${{ secrets.BOT_PRIVATE_KEY }} + + - name: Create a release + uses: softprops/action-gh-release@v1 + if: ${{ ! inputs.dry-run }} + with: + token: ${{ steps.generate-token.outputs.token }} + body: Version ${{ needs.sync.outputs.latest-release }} + tag_name: ${{ needs.sync.outputs.latest-release }}