diff --git a/.changeset/fuzzy-bees-applaud.md b/.changeset/fuzzy-bees-applaud.md new file mode 100644 index 00000000..3a12523b --- /dev/null +++ b/.changeset/fuzzy-bees-applaud.md @@ -0,0 +1,5 @@ +--- +"davinci-github-actions": major +--- + +Simplify the way yarn-install action ensures yarn.lock is unchanged after `yarn install` diff --git a/yarn-install/action.yml b/yarn-install/action.yml index 5961469f..c5002f53 100644 --- a/yarn-install/action.yml +++ b/yarn-install/action.yml @@ -112,34 +112,31 @@ runs: - name: Change registry in yarn.lock file to npm Artifact Registry if: "inputs.checkout-token && inputs.npm-gar-token && (contains(runner.name, 'inf-gha-runners') || contains(runner.name, 'ubuntu2204'))" shell: bash + working-directory: ${{ inputs.path }} run: | - # Create a copy of specific URLs (npmjs.org, @toptal and @topkit) and since they are fewer to restore them back at later steps - grep registry.npmjs.org ${{ inputs.path }}/yarn.lock | grep -v '/@toptal\|/@topkit' | awk '{print $2 " " $2}' > ${{ inputs.path }}/yarn.lock.tmp grep '/@toptal\|/@topkit' ${{ inputs.path }}/yarn.lock | awk '{print $2 " " $2}' >> ${{ inputs.path }}/yarn.lock.toptal - # Change the URLs to the new registry for files created in the previous steps - # Creates a TO/FROM list to be used when reverting back the URLs to the original registry - sed -i -e "s#https://registry.yarnpkg.com/#https://us-central1-npm.pkg.dev/toptal-ci/npm-registry/#" ${{ inputs.path }}/yarn.lock.tmp - sed -i -e "s#https://registry.npmjs.org/#https://us-central1-npm.pkg.dev/toptal-ci/npm-registry/#" ${{ inputs.path }}/yarn.lock.tmp sed -i -e "s#https://registry.yarnpkg.com/#https://us-central1-npm.pkg.dev/toptal-ci/npm-registry/#" ${{ inputs.path }}/yarn.lock.toptal sed -i -e "s#https://registry.npmjs.org/#https://us-central1-npm.pkg.dev/toptal-ci/npm-registry/#" ${{ inputs.path }}/yarn.lock.toptal - # Change the URLs to AR registry for all ocurrences - sed -i -e "s#https://registry.yarnpkg.com/#https://us-central1-npm.pkg.dev/toptal-ci/npm-registry/#g" ${{ inputs.path }}/yarn.lock - sed -i -e "s#https://registry.npmjs.org/#https://us-central1-npm.pkg.dev/toptal-ci/npm-registry/#g" ${{ inputs.path }}/yarn.lock + sed -i -e "s#https://registry.yarnpkg.com/#https://us-central1-npm.pkg.dev/toptal-ci/npm-registry/#g" yarn.lock + sed -i -e "s#https://registry.npmjs.org/#https://us-central1-npm.pkg.dev/toptal-ci/npm-registry/#g" yarn.lock - # Remove double quotes from the URLs - sed -i -e "s/\"//g" ${{ inputs.path }}/yarn.lock.tmp sed -i -e "s/\"//g" ${{ inputs.path }}/yarn.lock.toptal - # Revert the @toptal and @topkit packages to the original registry - # Working on revert fewer ocurrences (specific list) is faster than loop all the file while read -r line; do url1="$(awk '{ print $1 }' <<<"$line")" url2="$(awk '{ print $2 }' <<<"$line")" sed -i -e "s~${url1}~${url2}~" ${{ inputs.path }}/yarn.lock done < ${{ inputs.path }}/yarn.lock.toptal + - name: Capture yarn.lock file checksum + id: yarn-lock-checksum + shell: bash + working-directory: ${{ inputs.path }} + run: | + echo "checksum=$(cksum yarn.lock)" >> $GITHUB_OUTPUT + - name: yarn install shell: bash working-directory: ${{ inputs.path }} @@ -153,28 +150,11 @@ runs: sleep 10 # 10s wait time done - - - # Revert the URLs to the original registry - - name: Revert URLs to original registry - if: "inputs.checkout-token && inputs.npm-gar-token && (contains(runner.name, 'inf-gha-runners') || contains(runner.name, 'ubuntu2204'))" - shell: bash - run: | - # Revert specific URLs to npmjs.org - while read -r line; do - url1="$(awk '{ print $1 }' <<<"$line")" - url2="$(awk '{ print $2 }' <<<"$line")" - sed -i -e "s~${url1}~${url2}~" ${{ inputs.path }}/yarn.lock - done < ${{ inputs.path }}/yarn.lock.tmp - - # Revert the leftovers URLs to yarnpkg.org registry - sed -i -e "s#https://us-central1-npm.pkg.dev/toptal-ci/npm-registry/#https://registry.yarnpkg.com/#g" ${{ inputs.path }}/yarn.lock - # We are manually checking for the changes in yarn.lock file, because # the `--frozen-lockfile` flag is not working correctly in workspaces with yarn v1 # we can remove this step when we upgrade yarn or migrate to other package manager - - name: Check for changes + - name: Verify yarn.lock is unchanged shell: bash working-directory: ${{ inputs.path }} run: | - git diff --exit-code yarn.lock || (echo 'yarn.lock changed after yarn install. Please make sure to commit yarn.lock changes.' && exit 1) + [ "${{ steps.yarn-lock-checksum.outputs.checksum }}" = "$(cksum yarn.lock)" ] || (echo 'yarn.lock changed after yarn install. Please make sure to commit yarn.lock changes.' && exit 1)