chore: Update manifest.json version to 4.0.2 #62
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release Workflow | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'manifest.json' | |
- '.github/workflows/release-extension.yaml' | |
# TODO: Run the workflow without repo changing actions on workflow file change | |
# TODO: Upload the release artifacts to respective browser stores via API | |
jobs: | |
check_version: | |
runs-on: ubuntu-latest | |
outputs: | |
version_changed: ${{ steps.version_changed.outputs.changed }} | |
new_version: ${{ steps.get_new_version.outputs.version }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Read new version from manifest | |
id: get_new_version | |
run: | | |
VERSION=$(jq -r '.version' manifest.json) | |
echo "NEW_VERSION=$VERSION" >> $GITHUB_ENV | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
- name: Get old version from last release's manifest | |
id: get_old_version | |
run: | | |
git fetch --tags | |
PREV_TAG=$(git describe --tags --abbrev=0) | |
git checkout $PREV_TAG | |
VERSION=$(jq -r '.version' manifest.json) | |
echo "OLD_VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Print versions | |
run: | | |
echo "Old version: $OLD_VERSION" | |
echo "New version: $NEW_VERSION" | |
- name: Compare versions | |
id: version_changed | |
run: | | |
if [ "$(printf '%s\n' "$NEW_VERSION" "$OLD_VERSION" | sort -V | head -n1)" = "$OLD_VERSION" ] && [ "$NEW_VERSION" != "$OLD_VERSION" ]; then | |
echo "Version has been updated from $OLD_VERSION to $NEW_VERSION" | |
echo "changed=true" >> $GITHUB_OUTPUT | |
else | |
echo "No version update detected or new version is not greater than old version." | |
echo "changed=false" >> $GITHUB_OUTPUT | |
exit 0 | |
fi | |
update_files: | |
runs-on: ubuntu-latest | |
needs: check_version | |
if: needs.check_version.outputs.version_changed == 'true' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get changes since last release | |
id: get_changes | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
PREV_TAG=$(git describe --tags --abbrev=0) | |
CHANGELOG=$(git log $PREV_TAG..HEAD --merges --pretty=format:"%b" | sed ':a;N;$!ba;s/\n/\\n/g') | |
echo "CHANGELOG=${CHANGELOG}" >> $GITHUB_ENV | |
- name: Update README | |
run: | | |
VERSION=${{ needs.check_version.outputs.new_version }} | |
sed -E -i.bak 's/Version-[0-9]+\.[0-9]+(\.[0-9]+)?/Version-'${VERSION}'/' README.md | |
rm README.md.bak | |
- name: Check CHANGELOG version | |
id: check_changelog_version | |
run: | | |
VERSION=${{ needs.check_version.outputs.new_version }} | |
THIRD_LINE=$(sed -n '3p' CHANGELOG.md) | |
if echo "$THIRD_LINE" | grep -q "v$VERSION"; then | |
echo "CHANGELOG already contains the new version." | |
echo "skip_update=true" >> $GITHUB_ENV | |
else | |
echo "CHANGELOG needs to be updated." | |
echo "skip_update=false" >> $GITHUB_ENV | |
fi | |
- name: Update CHANGELOG | |
if: env.skip_update == 'false' | |
run: | | |
VERSION=${{ needs.check_version.outputs.new_version }} | |
FORMATTED_CHANGELOG=$(echo "$CHANGELOG" | sed 's/\\n/\n/g' | sed 's/^/ - /') | |
NEW_CHANGELOG=$(echo "- \`v${VERSION}\`\n${FORMATTED_CHANGELOG}\n" | sed 's/\\n/\n/g') | |
awk -v new_changelog="$NEW_CHANGELOG" 'NR==3{print new_changelog}1' CHANGELOG.md > tmpfile && mv tmpfile CHANGELOG.md | |
- name: Commit changes | |
if: env.skip_update == 'false' | |
run: | | |
git add . | |
git commit -m "Update README and CHANGELOG for v${{ needs.check_version.outputs.new_version }}" | |
- name: Create Pull Request | |
id: create_pr | |
uses: peter-evans/create-pull-request@v6 | |
with: | |
title: "Update README and CHANGELOG for v${{ needs.check_version.outputs.new_version }}" | |
branch: "update-docs-${{ needs.check_version.outputs.new_version }}" | |
commit-message: "Update README and CHANGELOG for v${{ needs.check_version.outputs.new_version }}" | |
body: "This PR updates the README and CHANGELOG files for the new version v${{ needs.check_version.outputs.new_version }}." | |
labels: documentation, github-actions | |
- name: Merge Pull Request | |
if: steps.create_pr.outputs.pull-request-number | |
run: | | |
gh pr merge "${{ steps.create_pr.outputs.pull-request-number }}" --squash --delete-branch | |
git fetch --all | |
git checkout main | |
git pull origin main | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Update firefox branch | |
run: | | |
git checkout firefox | |
git rebase main -X theirs | |
git push origin firefox --force | |
create_release: | |
runs-on: ubuntu-latest | |
needs: | |
- check_version | |
- update_files | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Zip Chrome extension | |
run: | | |
git fetch --all | |
git checkout main | |
VERSION=${{ needs.check_version.outputs.new_version }} | |
zip -r ../signature-sync-chrome-${VERSION}.zip . -x '.*' -x '__MACOSX' -x '*.md' | |
- name: Zip Firefox extension | |
run: | | |
git checkout . && git clean -fd | |
git checkout firefox | |
VERSION=${{ needs.check_version.outputs.new_version }} | |
zip -r ../signature-sync-firefox-${VERSION}.zip . -x '.*' -x '__MACOSX' -x '*.md' | |
- name: Create GitHub Release | |
id: create_release | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: v${{ needs.check_version.outputs.new_version }} | |
generate_release_notes: true | |
files: | | |
../signature-sync-chrome-${{ needs.check_version.outputs.new_version }}.zip | |
../signature-sync-firefox-${{ needs.check_version.outputs.new_version }}.zip |