From d874aeb7e00acd52eb07ff47abd9a520e0cd8a86 Mon Sep 17 00:00:00 2001 From: Gregor Lichtner Date: Wed, 15 May 2024 23:11:54 +0200 Subject: [PATCH] ci: added semantic release --- .github/workflows/ig-publish.yml | 76 ------------- .github/workflows/semantic-release.yml | 152 +++++++++++++++++++++++++ .releaserc.yaml | 21 ++++ 3 files changed, 173 insertions(+), 76 deletions(-) delete mode 100644 .github/workflows/ig-publish.yml create mode 100644 .github/workflows/semantic-release.yml create mode 100644 .releaserc.yaml diff --git a/.github/workflows/ig-publish.yml b/.github/workflows/ig-publish.yml deleted file mode 100644 index 509fa3554..000000000 --- a/.github/workflows/ig-publish.yml +++ /dev/null @@ -1,76 +0,0 @@ -name: ImplementationGuide Publisher - -# Controls when the action will run. -on: - # Triggers the workflow on push or pull request events but only for the main or master branch - push: - branches: - - main - - master - - staging - - 'v[0-9]+.[0-9]+*' # Approximates v[0-9]+.[0-9]+.* pattern - tags: - - 'v[0-9]+.[0-9]+*' # Trigger for semantic version tags (e.g., v1.2, v1.2.3) - - 'v[0-9]+.[0-9]+.*-*' # Additional pattern for pre-release versions (e.g., v1.2.3-snapshot) - pull_request: - branches: - - main - - master - - staging - - 'v[0-9]+.[0-9]+*' # Approximates v[0-9]+.[0-9]+.* pattern - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -jobs: - run-publisher: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 - - # read id, version and canonical from sushi-config.yaml - - name: Run read-yaml action - id: yaml-data - uses: CumulusDS/get-yaml-paths-action@v1.0.1 - with: - file: sushi-config.yaml - version: version - canonical: canonical - id: id - - # display outputs from read-yaml action - - name: Display read-yaml output - run: | - echo "id: ${{ steps.yaml-data.outputs.id }}" - echo "target url: ${{ steps.yaml-data.outputs.canonical }}" - echo "version: ${{ steps.yaml-data.outputs.version }}" - - - name: Run the IG publisher - uses: docker://hl7fhir/ig-publisher-base:latest - with: - args: ./scripts/run-ig-publisher.sh - - - # deploy implementation guide to github pages - - name: Deploy - if: (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./output - force_orphan: true - - # upload binaries to release - - name: Upload binaries to release - if: (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) - uses: svenstaro/upload-release-action@v2 - with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - file: ./output/package.tgz - asset_name: ${{ steps.yaml-data.outputs.id }}-${{ steps.yaml-data.outputs.version }}.tgz - tag: v${{ steps.yaml-data.outputs.version }} - release_name: Release v${{ steps.yaml-data.outputs.version }} - overwrite: true diff --git a/.github/workflows/semantic-release.yml b/.github/workflows/semantic-release.yml new file mode 100644 index 000000000..e9dc46576 --- /dev/null +++ b/.github/workflows/semantic-release.yml @@ -0,0 +1,152 @@ +name: Release Workflow + +on: + workflow_dispatch: + +jobs: + check-release: + runs-on: ubuntu-latest + concurrency: check-release + permissions: + id-token: write + contents: write + + outputs: + new_release_published: ${{ steps.semantic_release_version.outputs.new_release_published }} + new_release_version: ${{ steps.semantic_release_version.outputs.new_release_version }} + prerelease: ${{ steps.check-prerelease.outputs.prerelease }} + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "lts/*" + + - name: Install dependencies + run: | + sudo snap install yq + npm install @semantic-release/changelog @semantic-release/github + + - name: Semantic Release (Determine new version) + id: semantic_release_version + uses: cycjimmy/semantic-release-action@v4 + with: + extra_plugins: | + @semantic-release/changelog + @semantic-release/github + dry_run: true + ci: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Output new release version + run: | + echo Version: ${{ steps.semantic_release_version.outputs.new_release_version }} + echo new_release_published: ${{ steps.semantic_release_version.outputs.new_release_published }} + + - name: Check pre-release + id: check-prerelease + run: | + if [[ "${{ steps.semantic_release_version.outputs.new_release_version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "prerelease=false" >> $GITHUB_OUTPUT + else + echo "prerelease=true" >> $GITHUB_OUTPUT + fi + shell: bash + + - name: Echo Prelease + run: | + echo pre-release: ${{ steps.check-prerelease.outputs.prerelease }} + + perform-release: + needs: check-release + if: needs.check-release.outputs.new_release_published == 'true' + runs-on: ubuntu-latest + + permissions: + id-token: write + contents: write + + outputs: + new_release_published: ${{ steps.semantic_release.outputs.new_release_published }} + new_release_version: ${{ steps.semantic_release.outputs.new_release_version }} + new_release_git_tag: ${{ steps.semantic_release.outputs.new_release_git_tag }} + prerelease: ${{ needs.check-release.outputs.prerelease }} + ig_canonical: ${{ steps.yaml-data.outputs.canonical }} + ig_id: ${{ steps.yaml-data.outputs.id }} + ig_asset_filename: ${{ steps.generate-asset-filename.outputs.ig_asset_filename }} + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "lts/*" + + - name: Install dependencies + run: | + sudo snap install yq + npm install @semantic-release/changelog @semantic-release/github + + - name: Update sushi-config.yaml with new version + run: | + yq eval '.version = "${{ needs.check-release.outputs.new_release_version }}"' -i sushi-config.yaml + + # read id, version and canonical from sushi-config.yaml + - name: Read YAML file + id: yaml-data + run: | + VERSION=$(yq eval '.version' sushi-config.yaml) + ID=$(yq eval '.id' sushi-config.yaml) + CANONICAL=$(yq eval '.canonical' sushi-config.yaml) + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "id=$ID" >> $GITHUB_OUTPUT + echo "canonical=$CANONICAL" >> $GITHUB_OUTPUT + + - name: Generate asset filename + id: generate-asset-filename + run: echo "ig_asset_filename=${{ steps.yaml-data.outputs.id }}-${{ needs.check-release.outputs.new_release_version }}.tgz" >> $GITHUB_OUTPUT + + # display outputs from read-yaml action + - name: Display read-yaml output + run: | + echo "id: ${{ steps.yaml-data.outputs.id }}" + echo "target url: ${{ steps.yaml-data.outputs.canonical }}" + echo "version: ${{ steps.yaml-data.outputs.version }}" + echo "asset filename: ${{ steps.generate-asset-filename.outputs.ig_asset_filename }}" + + - name: Run the IG publisher + uses: docker://hl7fhir/ig-publisher-base:latest + with: + args: ./run-ig-publisher.sh + + - name: Move package.tgz to output directory + run: | + mkdir -p dist/ + mv ./output/package.tgz dist/${{ steps.generate-asset-filename.outputs.ig_asset_filename }} + + - name: Deploy to GitHub Pages + if: needs.check-release.outputs.prerelease == 'false' + uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./output + force_orphan: true + + - name: Semantic Release (Create release) + id: semantic_release + uses: cycjimmy/semantic-release-action@v4 + with: + extra_plugins: | + @semantic-release/changelog + @semantic-release/github + ci: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.releaserc.yaml b/.releaserc.yaml new file mode 100644 index 000000000..e681b838d --- /dev/null +++ b/.releaserc.yaml @@ -0,0 +1,21 @@ +--- +branches: + - '+([0-9])?(.{+([0-9]),x}).x' + - master + - main + - next + - next-major + - name: beta + prerelease: true + - name: alpha + prerelease: true + - name: "+(feat|fix|perf|chore|ci|docs|refactor|test|style)/**" + prerelease: "${name.split('/').slice(0, 2).join('-').toLowerCase()}" +plugins: + - "@semantic-release/commit-analyzer" + - "@semantic-release/release-notes-generator" + - "@semantic-release/changelog" + - + - "@semantic-release/github" + - assets: + - "dist/**"