diff --git a/.github/workflows/analyse-changed-packages.yaml b/.github/workflows/analyse-changed-packages.yaml deleted file mode 100644 index 5d10f6455..000000000 --- a/.github/workflows/analyse-changed-packages.yaml +++ /dev/null @@ -1,62 +0,0 @@ -name: Analyse changed packages - -on: - workflow_call: - inputs: - since: - description: 'Commit branch, tag or SHA to compare against' - required: false - default: ${{ github.event.before }} - type: string - outputs: - changed: - description: 'Changed packages (comma separated names)' - value: ${{ jobs.analyse_changed_packages.outputs.changed }} - changedPackages: - description: 'Changed packages (JSON array of objects with package and directory properties)' - value: ${{ jobs.analyse_changed_packages.outputs.changedPackages }} - -env: - DEFAULT_BRANCH: origin/master - DEFAULT_BRANCH_REF: refs/heads/master - -jobs: - analyse_changed_packages: - runs-on: ubuntu-latest - outputs: - changed: ${{ steps.changed-packages.outputs.changed }} - changedPackages: ${{ steps.changed-packages.outputs.changedPackages }} - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Read .node-version - id: node_version - run: echo "version=$(cat .node-version | tr -d 'v')" >> $GITHUB_OUTPUT - - - name: Set Up Node.js - uses: actions/setup-node@v3 - with: - node-version: ${{ steps.node_version.outputs.version }} - cache: 'pnpm' - - - run: pnpm global add turbo - - - name: Identifying Changed Bap-Services - id: changed-packages - run: | - turboChanges="" - if [ "${{ github.ref }}" = "${{ env.DEFAULT_BRANCH_REF }}" ]; \ - then turboChanges=$(turbo run build --dry-run=json --since="${{ inputs.since }}"); \ - else turboChanges=$(turbo run build --dry-run=json --since="${{ env.DEFAULT_BRANCH }}"); fi - changedPackages=$(node -e "const results = $turboChanges.tasks.map((task) => ({ package: task.package, directory: task.directory })); process.stdout.write(JSON.stringify(results));") - echo "$changedPackages" - changedPackagesFiltered=$(node -e "const fs = require('fs'); const results = $changedPackages.filter(({directory}) => {const private = JSON.parse(fs.readFileSync(\`./\${directory}/package.json\`, 'utf8')).private; return private === false || private === undefined;}); process.stdout.write(JSON.stringify(results));") - echo "$changedPackagesFiltered" - echo "changedPackages=$changedPackages" >> $GITHUB_OUTPUT - changed=$(node -e "const results = $changedPackagesFiltered.map(({package}) => package); process.stdout.write(JSON.stringify(results));") - echo "changed=$changed" >> $GITHUB_OUTPUT - - - name: Print Changed Packages - run: echo ${{ steps.changed-packages.outputs.changed }} diff --git a/.github/workflows/build-and-push.yaml b/.github/workflows/build-and-push.yaml index aa650be10..cd368b2cb 100644 --- a/.github/workflows/build-and-push.yaml +++ b/.github/workflows/build-and-push.yaml @@ -17,33 +17,65 @@ on: jobs: analyse-changed-packages: - uses: demokratie-live/democracy-development/.github/workflows/analyse-changed-packages.yaml@feature/changelog + runs-on: ubuntu-latest + outputs: + changed: ${{ steps.changed-packages.outputs.CHANGED }} + changedPackages: ${{ steps.changed-packages.outputs.CHANGED_PACKAGES }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 - push: + - uses: pnpm/action-setup@v2 + with: + version: 8 + run_install: false + + - run: | + echo SINCE=$(git rev-list --tags --max-count=1) >> $GITHUB_OUTPUT + echo $SINCE + id: since + + - run: | + pnpm list -r --json --filter "...[$SINCE]" | jq '[.[] | select(.private == false) | {name, path}]' > ./tmp.json + echo CHANGED_PACKAGES=$(jq '[.[] | .name]' ./tmp.json) >> $GITHUB_OUTPUT + echo $CHANGED_PACKAGES + id: changed-packages + env: + SINCE: ${{ steps.since.outputs.SINCE }} + + build-and-push: runs-on: ubuntu-latest environment: docker needs: [analyse-changed-packages] - if: ${{ needs.analyse-changed-packages.outputs.changed != '[]' && needs.analyse-changed-packages.outputs.changed != '' }} + if: ${{ needs.analyse-changed-packages.outputs.changedPackages != '[]'}} strategy: fail-fast: false matrix: - package: ${{fromJson(needs.analyse-changed-packages.outputs.changed)}} + package: ${{fromJson(needs.analyse-changed-packages.outputs.changedPackages)}} steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 + - uses: pnpm/action-setup@v2 + with: + version: 8 + run_install: false + - run: echo "package=${{ matrix.package }}" - name: get directory for package id: get-directory run: | - # Variablen setzen - matrix_package="${{ matrix.package }}" - changed_packages_json='${{ needs.analyse-changed-packages.outputs.changedPackages }}' - - # Verzeichnis mit jq finden - directory=$(echo "$changed_packages_json" | jq -r --arg package "$matrix_package" '.[] | select(.package == $package) | .directory') + directory=$(pnpm ls -r --json --filter $MATRIX_PACKAGE | jq '.[0] | .path') # Ausgabe - echo "$directory" echo "directory=$directory" >> $GITHUB_OUTPUT - - name: Checkout - uses: actions/checkout@v4 + env: + MATRIX_PACKAGE: ${{ matrix.package }} + + - run: echo "directory=${{ steps.get-directory.outputs.directory }}" + - name: Docker meta id: meta uses: docker/metadata-action@v5 diff --git a/.github/workflows/release-please.yaml b/.github/workflows/release-please.yaml deleted file mode 100644 index 3d71c4473..000000000 --- a/.github/workflows/release-please.yaml +++ /dev/null @@ -1,75 +0,0 @@ -on: workflow_dispatch - -permissions: - contents: write - pull-requests: write - -name: release-please - -jobs: - changeFinder: - runs-on: ubuntu-latest - outputs: - since: ${{ steps.interrogate.outputs.result }} - steps: - - uses: actions/checkout@v4 - - id: interrogate - uses: actions/github-script@v6 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - result-encoding: string - script: | - const {execSync} = require('child_process'); - const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/'); - const latestRelease = await github.rest.repos.getLatestRelease({ - owner, - repo - }); - console.log(`latest release: ${JSON.stringify(latestRelease.data)}`); - execSync('git pull --tags -q'); - execSync(`git reset --hard ${latestRelease.data.tag_name}`); - const sha = execSync('git rev-parse HEAD').toString().trim(); - console.log(`sha: ${sha}`) - return sha - - - run: | - echo "since=${{ steps.interrogate.outputs.result }}" - analyse-changed-packages: - needs: [changeFinder] - uses: demokratie-live/democracy-development/.github/workflows/analyse-changed-packages.yaml@master - with: - since: ${{ needs.changeFinder.outputs.since }} - - release-please: - runs-on: ubuntu-latest - environment: docker - needs: [changeFinder, analyse-changed-packages] - if: ${{ needs.analyse-changed-packages.outputs.changed != '[]' && needs.analyse-changed-packages.outputs.changed != '' }} - strategy: - fail-fast: false - matrix: - package: ${{fromJson(needs.analyse-changed-packages.outputs.changed)}} - steps: - - name: get directory for package - id: get-directory - run: | - # Variablen setzen - matrix_package="${{ matrix.package }}" - changed_packages_json='${{ needs.analyse-changed-packages.outputs.changedPackages }}' - - # Verzeichnis mit jq finden - directory=$(echo "$changed_packages_json" | jq -r --arg package "$matrix_package" '.[] | select(.package == $package) | .directory') - - # Ausgabe - echo "$directory" - echo "directory=$directory" >> $GITHUB_OUTPUT - - - uses: google-github-actions/release-please-action@v3 - with: - path: ${{ steps.get-directory.outputs.directory }} - token: ${{ secrets.GITHUB_TOKEN }} - release-type: node - monorepo-tags: true - package-name: ${{ matrix.package }} - command: github-release - bootstrap-sha: 416a41c6c73b0ed1e145ce798dce2cca51518721