Skip to content

Create Release

Create Release #5

name: Create Release
on:
push:
branches:
- main
paths:
- 'src/manifest.json'
workflow_dispatch: # allows to manually trigger the workflow_dispatch
jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt install jq
- name: Set up Git user
run: |
git config --global user.name 'github-actions'
git config --global user.email '[email protected]'
- name: Load .env file
run: |
set -o allexport
source .env
set +o allexport
# Export all loaded variables to GITHUB_ENV
for var in $(cat .env | grep -v '^#' | xargs); do
echo "$var" >> $GITHUB_ENV
done
- name: Extract version number
id: extract_version
run: echo "VERSION=$(jq -r '.version' src/manifest.json)" >> $GITHUB_ENV
- name: Check changelog for version entry
run: |
if ! grep -q "## v${VERSION}" "${CHANGELOG}"; then
echo "Error: ${CHANGELOG} does not contain a heading for version v${VERSION}."
exit 1
fi
- name: Build release
run: |
echo "Building release ${BASE_NAME}-$VERSION"
chmod +x scripts/build.sh
scripts/build.sh ${BASE_NAME} $VERSION
echo "Built release ${BASE_NAME}-$VERSION"
- name: Handle update files
run: |
echo "Updating update manifests for $BASE_NAME-$VERSION"
updatelink="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/v${VERSION}/${BASE_NAME}-${VERSION}.xpi"
update_hash="sha256:$(shasum -a 256 "${BUILD_DIR}/${BASE_NAME}-${VERSION}.xpi" | cut -d' ' -f1)"
jq --arg version "$VERSION" \
--arg updatelink "$updatelink" \
--arg updatehash "$update_hash" \
--arg pluginID "$PLUGIN_ID" \
'.addons[$pluginID].updates[0].version = $version |
.addons[$pluginID].updates[0].update_link = $updatelink |
.addons[$pluginID].updates[0].update_hash = $updatehash' \
"$UPDATE_TEMPLATE_FILE" > "$UPDATE_JSON_FILE"
cp "$UPDATE_JSON_FILE" "$UPDATE_RDF_FILE"
# Commit changes if any
git add "$UPDATE_JSON_FILE" "$UPDATE_RDF_FILE"
if ! git diff-index --quiet HEAD -- "$UPDATE_JSON_FILE" "$UPDATE_RDF_FILE"; then
git commit -m "Update $UPDATE_JSON_FILE and $UPDATE_RDF_FILE"
fi
- name: Get release notes
run: |
echo "Extract release notes from ${CHANGELOG}"
echo "## Changes" >> release-notes-${VERSION}.md
sed -n "/## v${VERSION}/,/^## /p" ${CHANGELOG} | sed '1d;$d' >> release-notes-${VERSION}.md
echo "Extracted release notes from ${CHANGELOG}"
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Creating release $VERSION"
gh release create v${VERSION} ${BUILD_DIR}/${BASE_NAME}-${VERSION}.xpi -t "v${VERSION}" --notes-file release-notes-${VERSION}.md
echo "Created release $VERSION"
- name: Cleanup
run: |
rm release-notes-${VERSION}.md
rm -rf ${BUILD_DIR}