From 43b482895e2c4f4b9d826b3be01e36148585f440 Mon Sep 17 00:00:00 2001 From: Mikkel Jakobsen Date: Fri, 8 Dec 2023 14:53:48 +0100 Subject: [PATCH 1/2] Splitting releasing in to two workflows Following the same pattern as in the designsystem --- .../create-release-on-branch-changes.yml | 85 +++++++++++++++++++ .github/workflows/create-release-on-tag.yml | 52 ++++++++++++ .github/workflows/release.yml | 68 --------------- 3 files changed, 137 insertions(+), 68 deletions(-) create mode 100644 .github/workflows/create-release-on-branch-changes.yml create mode 100644 .github/workflows/create-release-on-tag.yml delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/create-release-on-branch-changes.yml b/.github/workflows/create-release-on-branch-changes.yml new file mode 100644 index 0000000000..b8a40468c1 --- /dev/null +++ b/.github/workflows/create-release-on-branch-changes.yml @@ -0,0 +1,85 @@ +name: Create release on branch changes + +on: + push: + branches-ignore: + # Dependabot does not have permissions to create releases + - 'dependabot/**' + +jobs: + create_release_on_branch_changes: + name: "Create release on branch changes" + runs-on: ubuntu-latest + steps: + - name: Set release variables + id: resolve-release-vars + # Version 0.0.0-SHA is a schema that supports semantic versioning but + # should sink below proper versions. + # Output package.json to provide insight and help debugging + # Using branch names as tags allows other projects to track unreleased + # development. + run: | + RELEASE_BRANCH=$(echo ${GITHUB_REF#refs/heads/}) + RELEASE_SHA=${{ github.sha }} + TAG_NAME=$(echo "branch-${RELEASE_BRANCH}") + echo "RELEASE_BRANCH=$RELEASE_BRANCH" >> "$GITHUB_ENV" + echo "RELEASE_SHA=$RELEASE_SHA" >> "$GITHUB_ENV" + echo "TAG_NAME=$TAG_NAME" >> "$GITHUB_ENV" + echo "BUILD_VERSION=${RELEASE_BRANCH}-${RELEASE_SHA}" >> "$GITHUB_ENV" + echo "NPM_VERSION=0.0.0-${RELEASE_SHA}" >> "$GITHUB_ENV" + echo "DIST_FILENAME=dist-$RELEASE_BRANCH.zip" >> "$GITHUB_ENV" + + # Checkout the HEAD of the PR branch to get the latest commit message. + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Get release description + run: | + echo "RELEASE_DESCRIPTION=$(git show -s --format=%s)" >> "$GITHUB_ENV" + + - uses: actions/checkout@v4 + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + cache: 'yarn' + registry-url: 'https://npm.pkg.github.com' + + - run: yarn install --frozen-lockfile + + - name: Build artifacts + run: yarn build + env: + VERSION_FILE_NAME: ${{ github.repository }} + VERSION_FILE_VERSION: ${{ env.BUILD_VERSION }} + + - name: Zip project + run: | + zip -r -j ${{ env.DIST_FILENAME }} dist/ + + + - name: Delete existing releases + uses: dev-drprasad/delete-tag-and-release@v1.0 + with: + tag_name: ${{ env.TAG_NAME }} + github_token: ${{ secrets.GITHUB_TOKEN }} + + + - name: Create or update tag + uses: EndBug/latest-tag@v1.6.1 + with: + ref: ${{ env.TAG_NAME }} + + - name: Create release + id: create-release + uses: softprops/action-gh-release@v1 + with: + prerelease: true + target_commitish: ${{ env.RELEASE_SHA }} + tag_name: ${{ env.TAG_NAME }} + body: ${{ env.RELEASE_DESCRIPTION }} + files: ${{ env.DIST_FILENAME }} + + - name: Adding summary + run: | + echo "Release created 🚀😎 at: ${{ steps.create-release.outputs.url }}" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/create-release-on-tag.yml b/.github/workflows/create-release-on-tag.yml new file mode 100644 index 0000000000..55d023c3a9 --- /dev/null +++ b/.github/workflows/create-release-on-tag.yml @@ -0,0 +1,52 @@ +name: Create release on tag + +on: + push: + tags: + - "*" + +jobs: + create_release_on_tag: + name: "Create release on tag" + runs-on: ubuntu-latest + steps: + - name: Set release variables + id: resolve-release-vars + run: | + RELEASE_NAME=${{ github.ref_name }} + RELEASE_SHA=${{ github.sha }} + echo "RELEASE_NAME=$RELEASE_NAME" >> "$GITHUB_ENV" + echo "RELEASE_SHA=$RELEASE_SHA" >> "$GITHUB_ENV" + echo "BUILD_VERSION=${RELEASE_NAME}-${RELEASE_SHA}" >> "$GITHUB_ENV" + echo "NPM_VERSION=${RELEASE_NAME}-${RELEASE_SHA}" >> "$GITHUB_ENV" + echo "DIST_FILENAME=dist-$RELEASE_NAME-$RELEASE_SHA.zip" >> "$GITHUB_ENV" + + - uses: actions/checkout@v4 + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + cache: 'yarn' + registry-url: 'https://npm.pkg.github.com' + + - run: yarn install --frozen-lockfile + + - name: Build artifacts + run: yarn build + env: + VERSION_FILE_NAME: ${{ github.repository }} + VERSION_FILE_VERSION: ${{ env.BUILD_VERSION }} + + - name: Zip project + run: | + zip -r -j ${{ env.DIST_FILENAME }} dist/ + + - name: Create release + id: create-release + uses: softprops/action-gh-release@v1 + with: + files: ${{ env.DIST_FILENAME }} + + - name: Adding summary + run: | + echo "Release created 🚀😎 at: ${{ steps.create-release.outputs.url }}" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index b49cc20bcf..0000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,68 +0,0 @@ -name: Upload Release Asset - -on: - push: - branches-ignore: - # Dependabot does not have permissions to create releases - - 'dependabot/**' - -jobs: - build: - name: Upload Release Asset - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - # Required to fetch all commits and tags - fetch-depth: 0 - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - cache: 'yarn' - registry-url: 'https://npm.pkg.github.com' - env: - NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Install Dependencies - run: yarn install --frozen-lockfile - - name: Build artifacts - run: | - VERSION_FILE_NAME=$GITHUB_REPOSITORY \ - VERSION_FILE_VERSION=$(git describe --tags --exclude=latest) \ - yarn build - - name: Zip project - run: | - zip -r -j dist.zip dist/ - - name: Install GHR - run: | - curl --fail --silent --location --output ghr.tar.gz https://github.com/tcnksm/ghr/releases/download/v0.13.0/ghr_v0.13.0_linux_amd64.tar.gz - tar -zxf ghr.tar.gz - echo "./ghr_v0.13.0_linux_amd64" >> $GITHUB_PATH - - name: Create release with asset - if: startsWith(github.ref, 'refs/tags/') - env: - GITHUB_TOKEN: ${{ secrets.github_token }} - run: | - ghr -replace -delete -n ${GITHUB_REF:10} -c $GITHUB_SHA ${GITHUB_REF:10} dist.zip - - name: Update latest release - if: startsWith(github.ref, 'refs/heads/main') - env: - GITHUB_TOKEN: ${{ secrets.github_token }} - run: | - ghr -prerelease -replace -delete -n Latest -c main latest dist.zip - - - name: Build artifacts for branch release - run: | - VERSION_FILE_NAME=$GITHUB_REPOSITORY \ - VERSION_FILE_VERSION=${{ github.ref_name }} \ - yarn build - - name: Zip project - run: | - zip -r -j dist.zip dist/ - - - name: Release branch - if: startsWith(github.ref, "refs/heads/${{ github.ref_name }}") - env: - GITHUB_TOKEN: ${{ secrets.github_token }} - run: | - ghr -prerelease -replace -delete -n "release-${{ github.ref_name }}" -c "${{ github.ref_name }}" "release-${{ github.ref_name }}" dist.zip From 57d399fe0fc8ab63dfb6eec0687a041138d8a67c Mon Sep 17 00:00:00 2001 From: Mikkel Jakobsen Date: Fri, 8 Dec 2023 15:02:29 +0100 Subject: [PATCH 2/2] Remove unneeded NPM env vars --- .github/workflows/create-release-on-branch-changes.yml | 1 - .github/workflows/create-release-on-tag.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/create-release-on-branch-changes.yml b/.github/workflows/create-release-on-branch-changes.yml index b8a40468c1..7ff8a7bf50 100644 --- a/.github/workflows/create-release-on-branch-changes.yml +++ b/.github/workflows/create-release-on-branch-changes.yml @@ -26,7 +26,6 @@ jobs: echo "RELEASE_SHA=$RELEASE_SHA" >> "$GITHUB_ENV" echo "TAG_NAME=$TAG_NAME" >> "$GITHUB_ENV" echo "BUILD_VERSION=${RELEASE_BRANCH}-${RELEASE_SHA}" >> "$GITHUB_ENV" - echo "NPM_VERSION=0.0.0-${RELEASE_SHA}" >> "$GITHUB_ENV" echo "DIST_FILENAME=dist-$RELEASE_BRANCH.zip" >> "$GITHUB_ENV" # Checkout the HEAD of the PR branch to get the latest commit message. diff --git a/.github/workflows/create-release-on-tag.yml b/.github/workflows/create-release-on-tag.yml index 55d023c3a9..8031bf316d 100644 --- a/.github/workflows/create-release-on-tag.yml +++ b/.github/workflows/create-release-on-tag.yml @@ -18,7 +18,6 @@ jobs: echo "RELEASE_NAME=$RELEASE_NAME" >> "$GITHUB_ENV" echo "RELEASE_SHA=$RELEASE_SHA" >> "$GITHUB_ENV" echo "BUILD_VERSION=${RELEASE_NAME}-${RELEASE_SHA}" >> "$GITHUB_ENV" - echo "NPM_VERSION=${RELEASE_NAME}-${RELEASE_SHA}" >> "$GITHUB_ENV" echo "DIST_FILENAME=dist-$RELEASE_NAME-$RELEASE_SHA.zip" >> "$GITHUB_ENV" - uses: actions/checkout@v4