diff --git a/.github/workflows/release-integration.yml b/.github/workflows/release-integration.yml index 3663758..d986e4b 100644 --- a/.github/workflows/release-integration.yml +++ b/.github/workflows/release-integration.yml @@ -54,6 +54,7 @@ jobs: - name: Publish env: PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }} + RELEASES: ${{ inputs.releases }} run: | EXIT_CODE=0 @@ -65,7 +66,7 @@ jobs: fi } - for release in $(echo '${{ inputs.releases }}' | jq -r '.[] | @base64'); do + for release in $(echo $RELEASES | jq -r '.[] | @base64'); do PUBLISH_TAG=$(echo "$release" | base64 --decode | jq -r .publishTag) STATUS=$(each_release "$PUBLISH_TAG") if [[ "$STATUS" -eq 1 ]]; then diff --git a/package.json b/package.json index 405e3c4..ef3ef3c 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "templateOSS": { "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", "version": "4.21.3", - "publish": true + "publish": true, + "content": "./scripts/template-oss" }, "tap": { "nyc-arg": [ diff --git a/scripts/template-oss/_job-release-integration-yml.hbs b/scripts/template-oss/_job-release-integration-yml.hbs new file mode 100644 index 0000000..4596acd --- /dev/null +++ b/scripts/template-oss/_job-release-integration-yml.hbs @@ -0,0 +1,52 @@ +name: {{#if publish}}Publish{{else}}Check Publish{{/if}} +runs-on: ubuntu-latest +defaults: + run: + shell: bash +{{#if publish}} +permissions: + id-token: write +{{/if}} +steps: + {{#if publish}} + {{> stepsSetupYml jobCheckout=(obj ref="${{ fromJSON(inputs.releases)[0].tagName }}") }} + - name: Set npm authToken + run: npm config set '//registry.npmjs.org/:_authToken'=\${PUBLISH_TOKEN} + - name: Publish + env: + PUBLISH_TOKEN: $\{{ secrets.PUBLISH_TOKEN }} + RELEASES: $\{{ inputs.releases }} + {{else}} + {{> stepsSetupYml }} + - name: Check If Published + {{/if}} + run: | + EXIT_CODE=0 + + function each_release { + if {{#if publish}}npm publish --provenance --tag="$1"{{else}}npm view "$@" --loglevel=error > /dev/null{{/if}}; then + echo 0 + else + echo 1 + fi + } + + for release in $(echo $RELEASES | jq -r '.[] | @base64'); do + {{#if publish}} + PUBLISH_TAG=$(echo "$release" | base64 --decode | jq -r .publishTag) + STATUS=$(each_release "$PUBLISH_TAG") + {{else}} + SPEC="$(echo "$release" | base64 --decode | jq -r .pkgName)@$(echo "$release" | base64 --decode | jq -r .version)" + STATUS=$(each_release "$SPEC") + {{/if}} + if [[ "$STATUS" -eq 1 ]]; then + EXIT_CODE=$STATUS + {{#unless publish}} + echo "$SPEC ERROR" + else + echo "$SPEC OK" + {{/unless}} + fi + done + + exit $EXIT_CODE