Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release version 1.0 #7

Merged
merged 6 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions .github/workflows/dotnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,37 +138,37 @@ jobs:
# - uses: actions/checkout@v4
# - uses: gaurav-nelson/github-action-markdown-link-check@v1

# nuget-publish:
# runs-on: ubuntu-latest
# if: ${{ !github.event.repository.fork && github.ref == 'refs/heads/main' }}
# needs: [all-required-checks-complete]
# environment: release
# steps:
# - name: Download NuGet artifact
# uses: actions/download-artifact@v4
# with:
# name: nuget-package
# - name: Publish to NuGet
# run: dotnet nuget push "ShapeSifter.*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
nuget-publish:
runs-on: ubuntu-latest
if: ${{ !github.event.repository.fork && github.ref == 'refs/heads/main' }}
needs: [all-required-checks-complete]
environment: release
steps:
- name: Download NuGet artifact
uses: actions/download-artifact@v4
with:
name: nuget-package
- name: Publish to NuGet
run: dotnet nuget push "ShapeSifter.*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicates

# github-tag-and-release:
# runs-on: ubuntu-latest
# if: ${{ !github.event.repository.fork && github.ref == 'refs/heads/main' }}
# needs: [all-required-checks-complete]
# environment: release
# steps:
# - name: Generate app token
# id: app-token
# uses: actions/create-github-app-token@v1
# with:
# app-id: ${{ secrets.APP_ID }}
# private-key: ${{ secrets.APP_PRIVATE_KEY }}
# - uses: actions/checkout@v4
# with:
# token: ${{ steps.app-token.outputs.token }}
# - name: Download NuGet artifact
# uses: actions/download-artifact@v4
# - name: Tag and release packages
# env:
# GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
# run: bash .github/workflows/tag.sh
github-tag-and-release:
runs-on: ubuntu-latest
if: ${{ !github.event.repository.fork && github.ref == 'refs/heads/main' }}
needs: [all-required-checks-complete]
environment: release
steps:
- name: Generate app token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Download NuGet artifact
uses: actions/download-artifact@v4
- name: Tag and release packages
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
run: bash .github/workflows/tag.sh
63 changes: 62 additions & 1 deletion .github/workflows/tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,65 @@ case "$TAG" in
esac

# the empty target_commitish indicates the repo default branch
run_or_echo curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://github.com/repos/G-Research/ShapeSifter/releases -d '{"tag_name":"'"$TAG"'","target_commitish":"","name":"'"$TAG"'","draft":false,"prerelease":false,"generate_release_notes":false}'
curl_body='{"tag_name":"'"$TAG"'","target_commitish":"","name":"'"$TAG"'","draft":false,"prerelease":false,"generate_release_notes":false}'

# process_curl_error expects no arguments, but reads the output of `curl` from the file `curl_output.json`.
script_exit_code=-1
process_curl_error() {
jq_query='if .errors | length == 1 then .errors[0].code else null end'
if ! jq -r --exit-status "$jq_query" curl_output.json; then
echo "Unexpectedly got number of errors not equal to 1"
cat curl_output.json
script_exit_code=3
else
github_error="$(jq -r "$jq_query" curl_output.json)"
echo "Error reported by GitHub: $github_error"

if [ "$github_error" != "already_exists" ]; then
echo "Unrecognised error message"
script_exit_code=4
else
# Expected: we tried to make a release that already exists, which can happen when path filters prevent a new tag
script_exit_code=0
fi
fi
}

test_process_curl_error() {
echo "Running tests."

failed_output=$(cat <<'EOF'
{
"message": "Validation Failed",
"errors": [
{
"resource": "Release",
"code": "already_exists",
"field": "tag_name"
}
],
"documentation_url": "https://docs.github.com/rest/releases/releases#create-a-release"
}
EOF
)
echo "$failed_output" > curl_output.json
process_curl_error
if [ $script_exit_code != 0 ] ; then
echo "Test failure: got exit code $script_exit_code when we expected 0"
exit $script_exit_code
fi
Copy link
Contributor Author

@Smaug123 Smaug123 May 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't included a negative test here - I certainly could though. See https://github.com/Smaug123/WoofWare.Myriad/blob/6942ba42b977346bba8ddae44c879946b615c55f/.github/workflows/tag.sh for an example.


echo "Tests completed."
}

if [[ "$DRY_RUN" = "1" ]]; then
test_process_curl_error
else
if curl --fail-with-body -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://github.com/repos/G-Research/ShapeSifter/releases -d "$curl_body" > curl_output.json ; then
cat curl_output.json
echo "cURL succeeded."
else
process_curl_error
exit $script_exit_code
fi
fi
15 changes: 12 additions & 3 deletions ShapeSifter/version.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
{
"version": "0.4",
"version": "1.0",
"publicReleaseRefSpec": [
"^refs/heads/main$"
],
"pathFilters": null
}
"pathFilters": [
":/",
":^ShapeSifter.Test/",
":^/.github/",
":^/.config/",
":^/hooks/",
":^/analyzers/",
":^/.editorconfig",
":^/CONTRIBUTING.md"
]
}